0
0
Spring Bootframework~5 mins

@OneToMany relationship in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@OneToMany
B@ManyToOne
C@ManyToMany
D@OneToOne
Which attribute tells JPA which field owns the relationship in @OneToMany?
Acascade
BtargetEntity
CmappedBy
Dfetch
If you want changes in the parent entity to affect child entities automatically, which CascadeType should you use?
ACascadeType.ALL
BCascadeType.MERGE
CCascadeType.NONE
DCascadeType.DETACH
In a @OneToMany relationship, where is the foreign key stored?
AIn the 'one' side table
BNo foreign key is used
CIn a join table
DIn the 'many' side table
Which Java collection is commonly used to hold related entities in a @OneToMany relationship?
AMap
BList
CQueue
DStack
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.