One-to-one
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
@OneToOnewith a unique foreign key column on the owning side.- Typical example:
CustomerandCustomerProfile. - Inverse (
mappedBy) one-to-one cannot be lazy easily, because Hibernate must check if the row exists. @MapsIdshares the primary key with the parent and avoids a separate key.- Often an
@Embeddableor a plain column set is simpler.
Draft outline details
Demonstration
@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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.