HQL FromElement is not reused in some cases resulting in an additional join

Description

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).

The reason for incorrect SQL generation is because the fix for 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:

15867 (https://github.com/hibernate/hibernate-orm/commit/89cf22bab6bbd5aa317ca7a1df63624bb7b677c4)
15873 (https://github.com/hibernate/hibernate-orm/commit/7b943f0089f6f90cbf836b499e2da7c1ac9e9dea)

There was only 1 commit for trunk, which corresponds to the first commit on 3.3 (15867):
15866 (https://github.com/hibernate/hibernate-orm/commit/4ed21cbce5057cfdaf637bd7e98b3788f87e035d)

Applying the 2nd commit to 4.3 did not cause any unit test failures, and it fixes some regressions, including:

  • : Query translator generates an incorrect query with SELECT distinct + Order by + Implicit join

Environment

None

Status

Assignee

Gail Badner

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major
Configure