views:

18

answers:

1

Hi,

I need advice how to store model in spring mvc 3 with HIbernate (example on ilustration)

I have model

public class Customer{
        int id;
        String name;
        String surname;
        ArrayList<Contact> contacts;
...
getters, setters
}

Here is class Contact

public class Contact{
            int id;
            String address;
            String phonenumber;

    ...
    getters, setters
    }

You can see a Model has array list which contains contact information for Customer, When I am creating new customer i type name and surname to input fields and from existing contacts list I want to add contact for customer. (Add contact to ArrayList). And show selected contacts in view My question is how to remember what is already added to ArrayList contacts.

I should use Session, or temp file or hidden field in view or something else? What is best solution?

Thanks

A: 

you can keep a list of ids of all of the contacts that already exist in for the current customer.

you can query the db to get a list of contacts that don't have a relationship with the current customer id. (would need to see more of your model to finish that thought)

Aaron Saunders