Recall & Review
beginner
What does the @ManyToOne annotation represent in Spring Boot JPA?
It represents a many-to-one relationship between two entities, where many instances of one entity relate to one instance of another entity.
Click to reveal answer
beginner
In a @ManyToOne relationship, which side owns the foreign key in the database?
The entity with the @ManyToOne annotation owns the foreign key column in the database table.
Click to reveal answer
intermediate
How do you specify the foreign key column name in a @ManyToOne relationship?
You use the @JoinColumn annotation with the name attribute to specify the foreign key column name.
Click to reveal answer
intermediate
Can a @ManyToOne relationship be optional? How do you control this?
Yes, it can be optional. You control this by setting the optional attribute in @ManyToOne to true or false.
Click to reveal answer
intermediate
What is the default fetch type for @ManyToOne and why is it important?
The default fetch type is EAGER, meaning the related entity is loaded immediately with the owner entity. This affects performance and loading behavior.
Click to reveal answer
In a @ManyToOne relationship, which entity contains the foreign key column?
✗ Incorrect
The entity annotated with @ManyToOne owns the foreign key column in the database.
Which annotation is used to specify the foreign key column name in a @ManyToOne relationship?
✗ Incorrect
@JoinColumn is used to define the foreign key column name in the owning entity.
What is the default fetch type of a @ManyToOne relationship in Spring Boot JPA?
✗ Incorrect
The default fetch type for @ManyToOne is EAGER, which loads the related entity immediately.
How do you make a @ManyToOne relationship optional?
✗ Incorrect
Setting optional=true allows the relationship to be null, making it optional.
If you want to avoid loading the related entity immediately in a @ManyToOne relationship, what should you do?
✗ Incorrect
Setting fetch=FetchType.LAZY delays loading the related entity until it is accessed.
Explain how the @ManyToOne annotation works in Spring Boot JPA and how it relates to database foreign keys.
Think about how two tables connect with one foreign key column.
You got /4 concepts.
Describe how to control the optionality and fetch behavior of a @ManyToOne relationship.
Consider attributes inside the @ManyToOne annotation.
You got /4 concepts.