Many-to-Many Mapping — Concept Check
Questions on Many-to-Many Mapping. @ManyToMany uses a join table; prefer extracting the join table as an explicit entity (with extra columns like createdAt) to avoid limitations of the implicit join-table approach.
Questions in this quiz
7 questions on Many-to-Many Mapping — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer uses the implicit @ManyToMany approach for a Student-Course relationship. They notice that every time a student enrolls in a new course, all existing enrollments are deleted and re-inserted. What is causing this?
- AImproper mapping of @ManyToOne
- BLack of cascade settings
- CIncorrect use of @JoinTable
- DHibernate's default collection update behavior
2.In a Student-Course relationship, why might you prefer an explicit join entity over an implicit @ManyToMany?
- ATo avoid using @JoinTable
- BTo simplify the code
- CTo add extra columns like enrollment date
- DTo reduce database size
3.A developer wants to track when a student enrolls in a course. Which approach should they use?
- AUse @ManyToMany with a Set
- BUse an explicit join entity with an enrolledAt column
- CAdd a timestamp column to the implicit join table
- DAdd a timestamp to the Student entity
4.Which of the following is a disadvantage of using a List with @ManyToMany in Hibernate?
- ATriggers DELETE-all + INSERT-all on changes
- BRequires explicit join entity
- CForces eager loading
- DCannot use @JoinTable
5.A developer claims that using a List with @ManyToMany is more efficient than using a Set. What is the flaw in this claim?
- AList causes DELETE-all + INSERT-all on updates
- BSet does not support @ManyToMany
- CList is not supported in Hibernate
- DSet requires more memory
6.Why might a developer choose to use a Set instead of a List for a @ManyToMany relationship?
- ASet supports bidirectional relationships
- BSet requires less memory
- CSet is easier to implement
- DSet only inserts or deletes changed rows
7.In a Student-Course relationship using an explicit join entity, what happens when a student is removed from a course?
- ANo database operation occurs
- BAll enrollments are deleted and re-inserted
- CThe Student entity is deleted
- DA DELETE operation is executed for the specific enrollment