Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7599199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:36:12+00:00 2026-05-30T22:36:12+00:00

I have a data model that consists of a master – detail relationship where

  • 0

I have a data model that consists of a master – detail relationship where one Client can be related to many Address entities. I have generated the domain objects using Hibernate Tools and I get the following ( simplified ) classes.

Client.java

    @Entity
@Table(name="Client")
public class Client  implements java.io.Serializable {
     private Set<Address> addresses = new HashSet<Address>(0);

@OneToMany(fetch=FetchType.LAZY, mappedBy="client")
    public Set<Address> getAddresses() {
        return this.addresses;
    }

    public void setAddresses(Set<Address> addresses) {
        this.addresses = addresses;
    }

}

Address.java

@Entity
@Table(name="Address")
public class Address  implements java.io.Serializable {

     private AddressId id;
     private AddressType addressType;
     private Client client;
     private String addressLine1;



    @AttributeOverrides( {
        @AttributeOverride(name="clientId", column=@Column(name="ClientId", nullable=false) ), 
        @AttributeOverride(name="addressTypeId", column=@Column(name="AddressTypeId", nullable=false) ) } )
    public AddressId getId() {
        return this.id;
    }

    public void setId(AddressId id) {
        this.id = id;
    }

@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ClientId", nullable=false, insertable=false, updatable=false)
    public Client getClient() {
        return this.client;
    }

    public void setClient(Client client) {
        this.client = client;
    }    
}

I’m wanting to write a form that allows the user to add a client record and an address record at the same time, so, in my controller, I create a Client instance and put it into the ModelMap. I can happily refer to the fields on the Client object in my jsp, but have no idea how to refer to the fields in the Address object.

Code like <form:input type="text" path="addresses[0].addressLine1" /> results in the following exception

org.springframework.beans.InvalidPropertyException: Invalid property ‘addresses[0]’ of bean class [com.greenock.saltcam.hibernate.domain.Client]: Illegal attempt to get property ‘addresses’ threw exception; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property ‘addresses[0]’ of bean class [com.greenock.saltcam.hibernate.domain.Client]: Cannot get element with index 0 from Set of size 0, accessed using property path ‘addresses[0]’

This doesn’t strike me as unreasonable ( the set is empty ), but does that mean that I need to create an empty Address object in my controller and push it in to the Client object before passing it out to the jsp? What if I want to allow the user toadd an arbitrary number of addresses?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:36:13+00:00Added an answer on May 30, 2026 at 10:36 pm

    I would suggest creating a separate form-backing object:

    import org.springframework.util.AutoPopulatingList;
    public class ClientBackingBean {
      private Client client = new Client();
      private List<Address> addresses = new AutoPopulatingList<Address>(Address.class);
      ...
      <getters and setters>
    }
    

    Then put one of those in your ModelMap. You will just have to transfer the data from the backing bean to your actual model objects in the controller method that handles the form post. The nice thing about Spring’s AutoPopulatingList is that it will create entries as needed, so you could have javascript/jQuery in your JSP that creates addresses on the fly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have a data model called Widget . If I pick one
I have a data model that represents a weekly order. Eg. my order might
I have an Entity Data Model that I have created, and its pulling in
I have several Core Data model version that I have added to my .xcdatamodeld
I have set up a Core Data model that includes an entity, Item with
I have an Entity Data Model-based app that uses SQL Server CE 3.5 as
I have the following data model: I am writing a WCF service that needs
I have a model that I'm trying to retrieve an array of data from,
In my core data model I have a Person entity that has a to
I have a program that starts up and creates an in-memory data model and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.