OneToOne association cannot be fetched with a single query in Hibernate
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
Issue
- A
OneToOneassociation is defined between two entities (e.g.CustomerandAddress) - An HQL/JPAQL query like
select c from Customer c join fetch c.addressresults in two distinct SQL queries
Resolution
- This issue (dating back to Hibernate 3) has been Content from hibernate.atlassian.net is not included.addressed in the upstream Hibernate project and will be addressed in a future release1 of JBoss EAP.
- It may be feasible to work around the issue using a declared
ManyToOneassociation with code adapting the getter/setter to aOneToOnestyle interface (that can later be removed) for use by application code which references the entity.
Root Cause
This is a known defect (Content from hibernate.atlassian.net is not included.HHH-3930).
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.