Skip to content
Ameen Abozaid
Planned lessonJNR-030-L05

Cascades and orphan removal

  • Lesson 5 of 8
  • Junior
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: Order owns its OrderLines.
  • orphanRemoval = true deletes a child when it is removed from the parent's collection.
  • Do not cascade to entities with their own lifecycle: Order must not cascade to Product or Customer.
  • CascadeType.ALL everywhere can delete shared data by accident.
Draft outline details

Demonstration

java
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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.