0
0
Spring Bootframework~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What does the @OneToOne annotation represent in Spring Boot?
It represents a one-to-one relationship between two entities, meaning each instance of one entity is linked to exactly one instance of another entity.
Click to reveal answer
intermediate
How do you specify the owning side in a @OneToOne relationship?
The owning side is the entity that contains the foreign key and uses the @JoinColumn annotation to specify the column that joins the two tables.
Click to reveal answer
intermediate
What is the purpose of the mappedBy attribute in a @OneToOne relationship?
It is used on the inverse side to indicate that the relationship is controlled by the other entity's field, avoiding duplicate foreign keys.
Click to reveal answer
advanced
Can a @OneToOne relationship be lazy loaded in Spring Boot?
Yes, by default @OneToOne is eager, but you can set fetch=FetchType.LAZY to load the related entity only when accessed.
Click to reveal answer
beginner
What happens if you don't specify @JoinColumn in a @OneToOne relationship?
Spring Boot will create a default foreign key column with a generated name, which might not match your database schema or naming conventions.
Click to reveal answer
In a @OneToOne relationship, which side owns the foreign key?
AThe side with the @JoinColumn annotation
BThe side with the mappedBy attribute
CBoth sides share the foreign key equally
DNeither side owns the foreign key
What does the mappedBy attribute do in a @OneToOne relationship?
ARemoves the relationship
BDefines the owning side of the relationship
CCreates a new foreign key column
DSpecifies the inverse side and points to the owning side's field
How do you make a @OneToOne relationship load lazily?
ALazy loading is not possible with @OneToOne
BUse @Lazy annotation on the entity class
CSet fetch=FetchType.LAZY on the @OneToOne annotation
DSet fetch=FetchType.EAGER
What is the default fetch type for @OneToOne in Spring Boot?
AEAGER
BNONE
CLAZY
DMANUAL
If you omit @JoinColumn in a @OneToOne relationship, what happens?
AAn error occurs at runtime
BSpring Boot creates a default foreign key column
CThe relationship is ignored
DThe database schema is not updated
Explain how to set up a @OneToOne relationship between two entities in Spring Boot, including owning and inverse sides.
Think about which entity holds the foreign key and how to avoid duplicate keys.
You got /5 concepts.
    Describe the difference between the owning side and the inverse side in a @OneToOne relationship.
    Consider who 'owns' the link in the database.
    You got /4 concepts.