I want to automatically persist/merge Address
entities of persons. Once created, they should be updateable by any person, but not removed if a Person
is removed.
//each person can only have one address
@Entity
public class Person {
@ManyToOne
private Address address;
}
//one address can be assigned to multiple persons (eg family members)
@Entity
public class Address {
@OneToMany
private List<Person> persons;
}
Questions:
- How would I have to write the
cascade
annotations for this requirement? - How would I create those entities?
person.setAddress(address)
oraddress.getPersons().add(person)
?