Demo: cascade and orphan-removal surprises
On This Lesson 3 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
see what cascades and orphan removal really do; prepares JNR-030-LAB1.
Draft outline details
Step by step
- Remove one line from the order's list and commit; the log shows a
deletefor that line only. - Replace the whole list with
order.setLines(newList)and show the orphan-removal error ("collection was no longer referenced") and why to mutate the same collection. - Planned mistake: put
CascadeType.ALLonOrderLine.product; delete an order and watch it try to delete a product used elsewhere (constraint error). - Remove the cascade and show the order deletes alone.
- Summarize: cascade only parent-to-owned-children.
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.