Consider the following query which uses implicit joins:
{noformat}select r.id, flr.id, ur1.id, ur2.id, ur3.id from RootEntity r inner join r.firstLevelReference as flr left join UnrelatedEntity ur1 on ur1.id = flr.secondLevelReferenceA.id left join UnrelatedEntity ur2 on ur2.id = flr.secondLevelReferenceB.id left join UnrelatedEntity ur3 on ur3.id = flr.secondLevelReferenceB.thirdLevelReference.id {noformat}
Generated SQL is invalid as it references the alias in join conditions before it was declared:
{noformat}select r1_0.id, r1_0.firstLevelReference_id, u1_0.id, u2_0.id, u3_0.id from RootEntity r1_0 join FirstLevelReferencedEntity f1_0 on f1_0.id=r1_0.firstLevelReference_id left join UnrelatedEntity u1_0 on u1_0.id=f1_0.secondLevelReferenceA_id left join UnrelatedEntity u2_0 on u2_0.id=f1_0.secondLevelReferenceB_id left join UnrelatedEntity u3_0 on u3_0.id=s2_0.thirdLevelReference_id join SecondLevelReferencedEntityB s2_0 on s2_0.id=f1_0.secondLevelReferenceB_id{noformat}
and produces And exception happens :
{noformat}2023-08-04 13:32:02 WARN SqlExceptionHelper:145 - SQL Error: 42122, SQLState: 42S22 2023-08-04 13:32:02 ERROR SqlExceptionHelper:150 - Column "S2_0.THIRDLEVELREFERENCE_ID" not found; SQL statement:{noformat}
This query, however, works on Hibernate 5.x - the generated SQL is valid on this version .
Please see a reproducer attached :
[^hibernate-path-sql-issue- . zip]
|
|