Many-to-One Mapping — Concept Check
Questions on Many-to-One Mapping. @ManyToOne is the owning side and physically holds the FK column; it is the simplest and most common relationship — e.g., many Orders to one Customer.
Questions in this quiz
8 questions on Many-to-One Mapping — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In a bidirectional @ManyToOne relationship, what happens if you only set the child side without updating the parent collection?
- AThe parent collection in the L1 cache becomes stale.
- BThe child entity is automatically removed.
- CThe parent entity is updated with stale data.
- DThe database schema changes immediately.
2.A developer notices N+1 SELECT queries when loading orders and accessing customers. Which solution can fix this issue?
- AIncrease the database connection pool size.
- BAdd more indexes to the orders table.
- CSwitch to FetchType.EAGER for @ManyToOne.
- DUse JPQL JOIN FETCH to load associations.
3.What is the default fetch type for @ManyToOne relationships in JPA, and what should it be changed to?
- ALAZY, change to EAGER
- BLAZY, keep as LAZY
- CEAGER, keep as EAGER
- DEAGER, change to LAZY
4.When defining a @ManyToOne relationship, where is the foreign key column physically located?
- AOn the parent entity table
- BIn a view combining both tables
- CIn a separate join table
- DOn the child entity table
5.A developer adds an @OneToMany inverse relationship. What effect does this have on the database schema?
- AChanges the fetch type to EAGER
- BCreates a new table for the relationship
- CNo effect on the database schema
- DAdds a foreign key to the parent table
6.What is the purpose of the @JoinColumn annotation in a @ManyToOne relationship?
- ASpecifies the primary key column
- BIndicates the inverse side
- CDefines the fetch strategy
- DNames the foreign key column
7.In a bidirectional relationship, what is a potential issue if both sides are not kept in sync?
- AStale collections in the L1 cache
- BAutomatic schema updates
- CIncreased memory usage
- DData loss during transactions
8.Which annotation can help reduce the N+1 problem by specifying batch loading size?
- A@JoinColumn
- B@BatchSize
- C@EntityGraph
- D@Cascade