QuizzesOne-to-Many Mapping — Concept Check
intermediate
hibernate

One-to-Many Mapping — Concept Check

Questions on One-to-Many Mapping. @OneToMany on the parent with @ManyToOne on the child side creates a bidirectional relationship; a join column on the many side holds the FK; mappedBy avoids a redundant join table.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on One-to-Many Mapping — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.In a bidirectional @OneToMany relationship, which side owns the foreign key?

    • AThe one (parent) side with @OneToMany
    • BThe many (child) side with @ManyToOne
    • CBoth sides equally own the foreign key
    • DA separate join table owns the foreign key
  2. 2.What happens if you remove an OrderItem from an Order with orphanRemoval=true?

    • AThe OrderItem is deleted from the database
    • BThe OrderItem's foreign key is set to null
    • CThe OrderItem is moved to a separate table
    • DThe OrderItem remains in the database
  3. 3.A developer uses CascadeType.REMOVE on a large collection. What is a potential issue?

    • AHibernate loads all children into memory before deletion
    • BChildren are not deleted at all
    • CHibernate deletes all children in a single query
    • DThe parent entity is also deleted
  4. 4.What does the mappedBy attribute in @OneToMany signify?

    • AA join table should be created
    • BThe foreign key is managed by the other side
    • CThe parent side owns the foreign key
    • DThe relationship is unidirectional
  5. 5.Why might fetching two @OneToMany collections with JOIN FETCH cause issues?

    • AIt automatically deletes orphaned children
    • BIt creates a Cartesian product
    • CIt improves performance
    • DIt prevents lazy loading
  6. 6.A developer believes CascadeType.ALL includes orphanRemoval. Why is this incorrect?

    • AorphanRemoval only applies to detached entities
    • BorphanRemoval is deprecated
    • CorphanRemoval is separate and must be explicitly set
    • DCascadeType.ALL automatically includes orphanRemoval
  7. 7.When should you avoid using orphanRemoval=true?

    • AWhen children can belong to multiple parents
    • BWhen the parent has a small number of children
    • CWhen children are unique to one parent
    • DWhen the parent uses CascadeType.PERSIST
  8. 8.What is a potential pitfall of using entities in Sets without proper equals/hashCode?

    • AEntities will automatically be removed from the Set
    • BEntities will always be considered equal
    • CEntities may not be correctly identified in the Set
    • DEntities will be duplicated in the Set