0
0
Spring Bootframework~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What does the @ManyToMany annotation represent in Spring Boot?
It represents a relationship where multiple records in one entity relate to multiple records in another entity, like students enrolled in many courses and courses having many students.
Click to reveal answer
intermediate
How do you define the owning side of a @ManyToMany relationship?
The owning side is the entity that controls the relationship and usually has the @JoinTable annotation to define the join table and join columns.
Click to reveal answer
intermediate
What is the purpose of the @JoinTable annotation in a @ManyToMany relationship?
It defines the join table that holds foreign keys linking the two entities, specifying the table name and the join columns for both sides.
Click to reveal answer
advanced
Why is it important to manage both sides of a @ManyToMany relationship in code?
Because changes to the relationship must be reflected on both entities to keep data consistent and avoid unexpected behavior.
Click to reveal answer
advanced
What happens if you omit the mappedBy attribute in a bidirectional @ManyToMany relationship?
JPA treats both sides as owning sides, creating two separate join tables, which can cause data duplication and confusion.
Click to reveal answer
In a @ManyToMany relationship, which annotation specifies the join table?
A@JoinTable
B@JoinColumn
C@Entity
D@Table
What does the mappedBy attribute do in a @ManyToMany relationship?
AIndicates the inverse side that maps to the owning side
BDefines the join table name
CSpecifies the owning side of the relationship
DMarks the entity as a database table
Which side should have the @JoinTable annotation in a bidirectional @ManyToMany?
ABoth sides
BOnly the owning side
COnly the inverse side
DNeither side
What kind of database table does a @ManyToMany relationship create?
AA single table with foreign keys
BNo additional table
CTwo separate tables with no link
DA join table linking the two entity tables
If you forget to update both sides of a bidirectional @ManyToMany in code, what might happen?
AThe database will automatically fix it
BNo effect at all
CData inconsistency or unexpected behavior
DThe application will crash immediately
Explain how to set up a bidirectional @ManyToMany relationship between two entities in Spring Boot.
Think about how two friends share a group chat and both need to know about it.
You got /4 concepts.
    Describe the role of the join table in a @ManyToMany relationship and how it connects the entities.
    Imagine a guest list that shows which guests attend which parties.
    You got /4 concepts.