One-to-One Mapping — Concept Check
Questions on One-to-One Mapping. @OneToOne maps two entities with a shared or foreign-key strategy; use @MapsId to share the primary key between parent and child for an efficient 1:1 relationship.
Questions in this quiz
8 questions on One-to-One Mapping — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer notices that loading a User entity always triggers a query for UserProfile, despite using LAZY fetch. What might be causing this?
- AThe User entity is using EAGER fetch type.
- BThe UserProfile entity has a @MapsId annotation.
- CThe UserProfile entity is not mapped correctly.
- DThe User entity is on the non-owning side of the relationship.
2.In a @OneToOne relationship using a shared primary key, what is the primary advantage over using a foreign key?
- AIt simplifies the entity mapping configuration.
- BIt allows multiple child entities per parent.
- CIt supports bidirectional relationships more easily.
- DIt eliminates the need for a foreign key column.
3.A developer uses @OneToOne with FetchType.LAZY on both sides of a relationship. They observe unexpected SQL queries. What could be a solution?
- ARemove the @JoinColumn annotation.
- BMake the relationship unidirectional.
- CSwitch to FetchType.EAGER on both sides.
- DUse @LazyToOne on the non-owning side.
4.When using a foreign key strategy in a @OneToOne relationship, which entity should own the foreign key?
- AThe parent entity should own the foreign key.
- BBoth entities should own the foreign key.
- CNeither entity should own the foreign key.
- DThe child entity should own the foreign key.
5.A developer wants to ensure efficient joins in a @OneToOne relationship. Which strategy should they choose?
- ABidirectional mapping with mappedBy.
- BJoin table with a composite key.
- CForeign key with a unique constraint.
- DShared primary key using @MapsId.
6.In a @OneToOne relationship with a foreign key strategy, why is it important to make the relationship bidirectional?
- ATo ensure the parent entity is always loaded first.
- BTo avoid extra joins on the owning side.
- CTo allow lazy loading on both sides of the relationship.
- DTo maintain data integrity across both entities.
7.What is a potential issue when using LAZY fetch type in a @OneToOne relationship on the non-owning side?
- AThe relationship is automatically treated as EAGER.
- BThe associated entity is never loaded unless explicitly fetched.
- CThe child entity cannot be orphaned.
- DHibernate issues a query to check existence of the associated entity.
8.When using @MapsId in a @OneToOne relationship, what must be true about the child entity's primary key?
- AIt must be generated using a sequence.
- BIt must be a composite key.
- CIt must match the parent's primary key value.
- DIt can be any unique value.