Can somebody explain to me how to persist additions and removals to a collection of a parent entity. I want to:
1. outside of a session, add a Person to a Phone entity's Set<Person> 2. update(phone) - and insert a record in a PersonPhone join table 3. remove the newly added Person from the Phone entity's Set<Person> 4. in a separate session, update(phone) - and delete the record from the PersonPhone join table
When I initially load a Phone entity that contains a Set with one Person in it, adding another person to that set flags the set as dirty. The Set<Person> inside the Phone entity has storedSnapshot with a size of 1, which is different than the actual size, which is now 2. So the update succeeds and a new record is inserted into the PersonPhone join table. However, if, using the same entity, I now remove that newly added person, and attempt to update again in a separate session, a delete will not be performed, because the state of the Phone entity once again looks exactly like its storedSnapshot.
I'm still learning about automatic dirty checking, setReadOnly, evict, refresh, and clear. If anyone could give me a leg up, I would really appreciate it. So far, I have not gotten Hibernate to ignore what end up being inaccurate storedSnapshots. Is there a way to force an update in my scenario?
|