Demo: mapping Order and OrderLine as an aggregate
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
map the order aggregate; prepares JNR-030-LAB1.
Draft outline details
Step by step
- Create
Order(id, customer, status, createdAt) andOrderLine(id, product, quantity, unitPrice). - Add
@ManyToOne(LAZY)fromOrdertoCustomerand fromOrderLinetoProduct. - Add
lineswithcascade = ALL, orphanRemoval = trueand theaddLine/removeLinehelpers. - Planned mistake: add a line to the list without setting
line.setOrder(this); show the null foreign key error and fix it with the helper. - Save an order and read the SQL log: one order insert, then one insert per line.
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.