Yoann Rodière (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjlhZDZjMjk5...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16219?atlOrigin=eyJpIjoiNjlhZD...
) HHH-16219 (
https://hibernate.atlassian.net/browse/HHH-16219?atlOrigin=eyJpIjoiNjlhZD...
) Lazy loading of association involving loading of other, eager associations leads to
unwanted loading beyond max_fetch_depth (
https://hibernate.atlassian.net/browse/HHH-16219?atlOrigin=eyJpIjoiNjlhZD...
)
Issue Type: Bug Affects Versions: 6.2.0.CR2 Assignee: Unassigned Components:
hibernate-core Created: 22/Feb/2023 08:59 AM Fix Versions: 6.2.0 Priority: Major Reporter:
Yoann Rodière (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
With the following model:
@Entity(name = "entitya")
public static class EntityA {
@Id
private Integer id;
@OneToOne
private EntityB entityB1;
@OneToOne
private EntityB entityB2;
// ... Getters, setters ...
}
@Entity(name = "entityb")
public static class EntityB {
@Id
private Integer id;
@OneToOne(mappedBy = "entityB1", fetch = FetchType.LAZY)
private EntityA entityA1;
@OneToOne(mappedBy = "entityB2", fetch = FetchType.LAZY)
private EntityA entityA2;
// ... Getters, setters ...
}
Assuming a max_fetch_depth of 1, calling EntityB.getEntityA1() will execute the following
query:
select e2_0.id,e3_0.id,e4_0.id,e5_0.id,e6_0.id,e7_0.id
from entityb e1_0
left join entitya e2_0 on e1_0.id=e2_0.entityB1_id
left join entityb e3_0 on e3_0.id=e2_0.entityB1_id
left join entityb e4_0 on e4_0.id=e2_0.entityB2_id
left join entitya e5_0 on e1_0.id=e5_0.entityB2_id
left join entityb e6_0 on e6_0.id=e5_0.entityB1_id
left join entityb e7_0 on e7_0.id=e5_0.entityB2_id
where e1_0.id=?
That’s 6 joins, but I would have expected at most three joins, one for the lazy
association and two for the eager associations in EntityA.
(
https://hibernate.atlassian.net/browse/HHH-16219#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16219#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100216- sha1:64a4cf6 )