0
0
Spring Bootframework~5 mins

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

Choose your learning style9 modes available
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?
ANeither entity contains the foreign key
BThe entity with the @ManyToOne annotation
CBoth entities share the foreign key
DThe entity with the @OneToMany annotation
Which annotation is used to specify the foreign key column name in a @ManyToOne relationship?
A@JoinColumn
B@Column
C@ForeignKey
D@PrimaryKeyJoinColumn
What is the default fetch type of a @ManyToOne relationship in Spring Boot JPA?
ANONE
BLAZY
CDEFAULT
DEAGER
How do you make a @ManyToOne relationship optional?
ASet optional=true
BUse @Nullable annotation
CSet optional=false
DUse @NotNull annotation
If you want to avoid loading the related entity immediately in a @ManyToOne relationship, what should you do?
ASet fetch=FetchType.EAGER
BRemove the @ManyToOne annotation
CSet fetch=FetchType.LAZY
DUse @Transient annotation
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.