I have the following entities with a parent-child relationship:
public class Parent {
@Id @GeneratedValue String id;
@Version Long version;
@OneToMany(mappedBy = "parent", orphanRemoval = true)
@Cascade({CascadeType.ALL})
Set<Child> children;
// getters and setters
}
public class Child {
@Id @GeneratedValue String id;
@ManyToOne
@JoinColumn("parent_id")
Parent parent;
// getters and setters
}
- I retrieve a Parent for edit on the web UI by copy properties to a ParentDto, which has a list of ChildDtos.
- Once I'm done editing, I send the ParentDto object back and copy all properties into a new Parent object (parent) with a new HashSet to store the Children created from the list of ChildDtos.
- Then I call getCurrentSession().update(parent);
The problem
I can add children, update children, but I can't delete children. What is the issue here and how do I resolve it?
Thanks in advance.