Criteria and Entity graph generates same join clause twice

Description

During migration from spring boot version 2 to version 3 we have found different behavior between Hibernate 5 and 6. We are using Entity graph and Specification (Criteria). Similar scenario can be seen in provided test case:

SQL generated by Hibernate 5:

SQL generated by Hibernate 6:

Hibernate 6 generates same join twice - first time from Criteria and second time from Entity Graph and when you want to sort by column from table in join then it causes crash.

Order by expression "A1_0.ID" must be in the result list in this case.

Discussed on hibernate forum ( )

Attachments

1

Activity

Show:

Robert Mazgut January 11, 2024 at 8:14 AM

You are right on this particular select, but this was just first example. I focused on problem which is described. First case I tested was inner join, but then I decided to test also left join case, just to know whether the result is the same. Unfortunately I used left join as example in description of this bug, but behavior is the same for both inner and left join. 

Gavin King January 9, 2024 at 1:56 PM

Note that the query here is pretty weird/wrong. It’s not normal to use left join to join a table which is then used as a restriction in the where clause. That’s not really an outer join, it’s implicitly an inner join.

Fixed

Details

Assignee

Reporter

Labels

Worked in

Components

Sprint

Fix versions

Affects versions

Priority

Created January 9, 2024 at 1:25 PM
Updated February 3, 2025 at 9:12 AM
Resolved January 24, 2024 at 5:33 PM