Skip to content
Ameen Abozaid
Planned lessonJNR-030-L03

One-to-one

  • 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

map a one-to-one link and know its trade-offs.

Planned topics

  • @OneToOne with a unique foreign key column on the owning side.
  • Typical example: Customer and CustomerProfile.
  • Inverse (mappedBy) one-to-one cannot be lazy easily, because Hibernate must check if the row exists.
  • @MapsId shares the primary key with the parent and avoids a separate key.
  • Often an @Embeddable or a plain column set is simpler.
Draft outline details

Demonstration

java
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_id", unique = true)
private Customer customer;

Check your understanding

When might an embeddable be better than one-to-one?

Show answer

When the data has no identity and lives in the same 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.