Recall & Review
beginner
What does the @OneToMany annotation represent in Spring Boot?
It represents a relationship where one entity is linked to many instances of another entity, like one author having many books.
Click to reveal answer
intermediate
In a @OneToMany relationship, which side owns the relationship by default?
The "many" side owns the relationship by default, meaning it holds the foreign key in the database.
Click to reveal answer
intermediate
How do you specify the field that owns the relationship in a @OneToMany mapping?
You use the 'mappedBy' attribute on the @OneToMany annotation to point to the owning field on the 'many' side.
Click to reveal answer
intermediate
What is the effect of using CascadeType.ALL in a @OneToMany relationship?
It means that operations like save, update, or delete on the parent entity will automatically apply to the related child entities.
Click to reveal answer
beginner
Why is it important to use a collection type like List or Set in a @OneToMany relationship?
Because one entity relates to many others, a collection holds all related entities, allowing easy access and management.
Click to reveal answer
What annotation is used on the 'one' side to define a one-to-many relationship?
✗ Incorrect
The @OneToMany annotation defines the 'one' side of a one-to-many relationship.
Which attribute tells JPA which field owns the relationship in @OneToMany?
✗ Incorrect
The 'mappedBy' attribute points to the owning field on the 'many' side.
If you want changes in the parent entity to affect child entities automatically, which CascadeType should you use?
✗ Incorrect
CascadeType.ALL applies all operations like save, update, and delete to child entities.
In a @OneToMany relationship, where is the foreign key stored?
✗ Incorrect
The foreign key is stored in the 'many' side table pointing back to the 'one' side.
Which Java collection is commonly used to hold related entities in a @OneToMany relationship?
✗ Incorrect
List or Set are commonly used to hold multiple related entities.
Explain how the @OneToMany annotation works in Spring Boot and how it connects two entities.
Think about how one author can have many books and how the database knows this.
You got /4 concepts.
Describe the role of cascade types in a @OneToMany relationship and why they are useful.
Imagine deleting an author and wanting all their books deleted automatically.
You got /4 concepts.