Dear Hibernate developers, please,
change behaviour of Session.update function with object mapping one-to-many bidirectional with all-delete-orphan.
Don't rely on hibernate implementation of Set to be able to delete orphaned childs from Set owned by Parent.
It is possible to do it relatively easy:
memorySet = Parent.getChilds()
loadedSet = select all childs from db for given parent
for all childs in memorySet that have primaryKey not null do update & remove them from laodedSet
for all childs in memorySet that have primaryKey null do insert & remove them from loadedSet
for rest of childs in loadedSet do delete
Thanks very much in advance.
mappings in Parent and Child objects:
Code:
/**
* @hibernate.set inverse="true" cascade="all-delete-orphan" lazy="true"
* @hibernate.collection-key column="parentId"
* @hibernate.collection-one-to-many class="com.domainmodel.Child"
*/
public Set getChilds() {
return childs;
}
/**
* @hibernate.many-to-one column="parentId" class="com.domainmodel.Parent" not-null="true"
*/
public Parent getParent() {
return parent;
}
keywords:
deleting childs from one-to-many bidirectional relation
how to delete childs from one-to-many bidirectional relation
delete of childs from one-to-many bidirectional relation does not work