Cascades and orphan removal
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
choose cascade types on purpose.
Planned topics
- Cascade passes an operation (
persist,remove, ...) from parent to children. - It fits an aggregate:
Orderowns itsOrderLines. orphanRemoval = truedeletes a child when it is removed from the parent's collection.- Do not cascade to entities with their own lifecycle:
Ordermust not cascade toProductorCustomer. CascadeType.ALLeverywhere can delete shared data by accident.
Draft outline details
Demonstration
order.removeLine(line); // removed from the list
// at flush: delete from order_line where id = ?Check your understanding
Should Order cascade REMOVE to Product?
Show answer
No; products live on their own.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.