Hi,
Quote:
I start off from a java object of parent (not 'connected' to database). I set a Collection of children. I call the update function. What I notice is that, the older children of the parent still exist. And new children are added.
IMHO: This not 'connected' object is actually a 'detached object' (hibernate name). Why ? Because of the 'older children' - this means the parent was loaded from database once.
When calling session.update the 'detached object' become a 'persistent object'. And if the parent-child relationship is well build - hibernate should take care of everything. The only thing and it's a must is to call parent.getChildren().clear(). Why ?
Quote:
By default, Hibernate does not navigate an association when searching for transient
or detached objects, so saving, deleting, or reattaching a Category won’t affect
the child category objects.
Quote:
cascade="all-delete-orphan" means the same as cascade="all" but, in addition,
Hibernate deletes any persistent entity instance that has been removed
(dereferenced) from the association (for example, from a collection).