Skip to content
Ameen Abozaid
Planned lessonJNR-028-L03

Embeddables and value objects

  • Lesson 3 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

store a value object in the owner's table.

Planned topics

  • A value object has no identity of its own; Money is just amount plus currency.
  • @Embeddable marks the class; @Embedded uses it in an entity.
  • Its fields become columns of the owner's table (granularity solved).
  • Rename columns with @AttributeOverride if the same embeddable appears twice.
  • Make value objects immutable.
Draft outline details

Demonstration

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

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.