HQL FromElement is not reused in some cases resulting in an additional join
There are some cases where Hibernate does not reuse an HQL FromElement when it should, resulting in the same join being duplicated in the generated SQL:
Here are some examples:
1) a to-one association is referenced in the SELECT clause and explicitly joined in the FROM clausee;
2) SELECT DISTINCT, WHERE, and ORDER BY clauses contain an implicit join;
3) When there are 2 or more to-one associations and at least 1 is implicitly joined, a non-ANSI join can be in the middle of ANSI joins, causing an exception on those DBs that don't support this ( HHH-6326 Open ).
The reason for incorrect SQL generation is because the fix for HHH-3749 Closed was applied to 3.2 and 3.3 branches properly, but was only partially fixed in the trunk (which ultimately was branched for 3.5).
There were 2 commits for 3.3:
There was only 1 commit for trunk, which corresponds to the first commit on 3.3 (15867):
Applying the 2nd commit to 4.3 did not cause any unit test failures, and it fixes some regressions, including:
- HHH-8290 Closed : Query translator generates an incorrect query with SELECT distinct + Order by + Implicit join