Embeddables and value objects
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
store a value object in the owner's table.
Planned topics
- A value object has no identity of its own;
Moneyis just amount plus currency. @Embeddablemarks the class;@Embeddeduses it in an entity.- Its fields become columns of the owner's table (granularity solved).
- Rename columns with
@AttributeOverrideif the same embeddable appears twice. - Make value objects immutable.
Draft outline details
Demonstration
@Embeddable
public record Money(
@Column(name = "price_amount") BigDecimal amount,
@Column(name = "price_currency", length = 3) String currency) {}
// in Product:
@Embedded private Money price;Check your understanding
Does an embeddable get its own table?
Show answer
No; its columns live in the owner's table.
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.