Eager fetch performed for OneToOne association in Hibernate
Issue
-
Two classes have been defined with a OneToOne association between them
@Entity public class Employee { ... @OneToOne(mappedBy = "employee") private Task task; ... } @Entity public class Task { ... @OneToOne @JoinColumn(name = "employee_name") private Employee employee; ... } -
When the side that does not own the foreign key is loaded from the database (e.g. an "employee"), the side which owns the foreign key (e.g. "a task") is (eagerly) fetched from the database even if it is not directly referenced by the HQL query or otherwise explicitly accessed.
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 5
- 6
- 7
- Hibernate
- 3
- 4
- 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.