How do CascadeType.REMOVE and orphanRemoval differ?
Short answer
CascadeType.REMOVE deletes children when the parent is deleted. orphanRemoval = true deletes a child when it is detached from the parent, even though the parent stays.
3 points to say:
- Use
orphanRemovalonly when a child belongs to one parent. - With
orphanRemoval,clear()+addAll(); never assign a new list. - Cascade is Hibernate behaviour, not a database constraint.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.