I have a City with a bi-directional @OneToMany association to Person:
Code:
@OneToMany(mappedBy = "city")
@OptimisticLock(excluded = true) // No dirty checking
public List<Person> getPersons()
So there's no cascading.
However when I merge a detached City back into the persistent context, I see it refresh (= select) every detached Person of the detached city.
How can I avoid this?
It has 2 problems:
- It creates an n+1 query problem, which is a big problem for a City with 500+ persons.
- If meanwhile one of those Persons are deleted, it throws an EntityNotFoundException on the merge of the city, while it should just update the properties of the city and don't care about the persons.
Thanks for any and all help :)