Brian Leierzapf (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ee5183...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiM2M0OWQ2ZGE5...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17042?atlOrigin=eyJpIjoiM2M0OW...
) HHH-17042 (
https://hibernate.atlassian.net/browse/HHH-17042?atlOrigin=eyJpIjoiM2M0OW...
) JoinType Doesn't Work (Using JoinType.LEFT) (
https://hibernate.atlassian.net/browse/HHH-17042?atlOrigin=eyJpIjoiM2M0OW...
)
Issue Type: Bug Affects Versions: 6.2.7 Assignee: Unassigned Components:
hibernate-entitymanager, query-criteria Created: 07/Aug/2023 19:36 PM Environment:
Hibernate Persistance Criteria JoinType - Production Priority: Major Reporter: Brian
Leierzapf (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ee5183...
)
Per Beckov in the Hibernate form I created a test case for my issue:
Fork @
https://github.com/bleierzapf/hibernate-test-case-templates
Both the Hibernate 5 and 6 projects are populated with the same classes and tests to show
the different results between the 2 versions.
In Hibernate 5, JoinType.LEFT worked fine in a criteria builder statements with:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Action> query = cb.createQuery(Action.class);
Root<Action> from = query.from(Action.class);
from.join(Action_.LOCATION, JoinType.LEFT);
from.join(Action_.LEAD, JoinType.LEFT);
However, now in Hibernate 6, the resulting sql doesn’t acknowledge the join at all.
Hibernate 5 Query:
select
action0_.id as id1_0_,
action0_.action_details as action_d2_0_,
action0_.lead_id as lead_id3_0_,
action0_.location as location4_0_
from
actions action0_
left outer join
location location1_
on action0_.location=location1_.id
left outer join
leads lead2_
on action0_.lead_id=lead2_.id
where
location1_.Active=true
or lead2_.Active=true
Hibernate 6:
select
a1_0.id,
a1_0.action_details,
a1_0.lead_id,
a1_0.location
from
actions a1_0
join
location l3_0
on l3_0.id=a1_0.location
join
leads l4_0
on l4_0.id=a1_0.lead_id
where
l3_0.Active
or l4_0.Active
As you can see, the Hibernate 6 query is only creating joins and this is causing no
results to return as I have the Action entity which is linked to either a Location or a
Lead, never both, so this requires as left join to produce a result.
(
https://hibernate.atlassian.net/browse/HHH-17042#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17042#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#100233- sha1:7fb7fe8 )