Problem with sharing objects in different lists
Hi,
i have a problem with my model. I have 2 database tables: projects and persons. They have a many to many relationship. My model looks like this:
In class Project i save a list of Persons in this Project:
Code:
private List<Person> persons;
other properties like name, description, etc ...
In class ProjectsModel i save the list of all Projects:
Code:
private List<Project> projects = new ArrayList<Project>();
private void readProjects() {
Query query = em.createQuery("select p from Project p");
projects = query.getResultList();
}
In class PersonsModel i save the list of all Persons:
Code:
private List<Project> persons = new ArrayList<Person>();
private void readPersons() {
Query query = em.createQuery("select p from Person p");
this.persons = query.getResultList();
}
And a Person class of course with properties of a person.
Cause of the queries i now have 2 different models. Changing a property of a Person from the PersonsModel instance doesn't change the persons property in a personslist in a project cause they are different objects. And i don't know how to change it so that persons in a project are only pointing to the appropriate persons in personsModel and thus sharing the same objects.
Any suggestions would help greatly :)