Many-to-one: the default relationship
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 the most common relationship correctly.
Planned topics
- Many
Products belong to oneCategory:@ManyToOneon the product. - The table holding the foreign key is the "many" side (
product.category_id). @JoinColumnnames the foreign key column.- Use
fetch = FetchType.LAZY; the default for@ManyToOneisEAGER, which often causes extra queries. - Start here; most designs need only this plus a query.
Draft outline details
Demonstration
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "category_id")
private Category category;Check your understanding
Which table holds the foreign key in a many-to-one?
Show answer
The "many" side.
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.