In my application, a hibernate operation goes like this. The application updates a parent entity with new values from the request and deletes all the existing (previously insert
Your last snippet of Java code doesn't compile. I guess it looks like
parent.getChilds().clear(); // note: you should name it children rather than childs
parent.setChilds(someNewSetOfChildren):
Don't do the last instruction. Instead of replacing the set by another one, clear the set and add the new children to the cleared set:
parent.clearChildren();
parent.addChildren(someNewSetOfChildren);
where the methods are defined as:
public void clearChildren() {
this.children.clear();
}
public void addChildren(Collection children) {
this.children.addAll(children);
}
The setChildren method should be removed completely, or it should be replaced with the following implementation:
public void setChildren(Collection children) {
this.children.clear();
this.children.addAll(children);
}