New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HHH-13058 Fix issue left join root cannot be replaced by correlated parent in subquery #3528
Conversation
0985d91
to
fa3e746
Compare
fa3e746
to
61cc4f0
Compare
61cc4f0
to
c7ded44
Compare
Note for v6 porting. The code changes might not be applicable to v6 and nontrivial v6 specific tweaking might be needed, but the testing case is invaluable. |
512083f
to
66d8c68
Compare
add412c
to
a1d6194
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires some further work as the implementation produces SQL queries that aren't as efficient as before.
hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/AbstractFromImpl.java
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java
Outdated
Show resolved
Hide resolved
a1d6194
to
6ce0309
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java
Outdated
Show resolved
Hide resolved
6ce0309
to
e3eb27a
Compare
…arent in subquery
e3eb27a
to
2662edf
Compare
https://hibernate.atlassian.net/browse/HHH-13058
The current correlated subquery ignores the first left join and ends up with 'inner join' instead invariably. So suppose for the below entities:
Note that
@ManyToOne
'soptional
istrue
by default.the following Criteria would skip the
Task
withoutPatient
:because internally the jpasql generated is:
Note that
generatedAlias1 is null
can never be true for the left join from Task to Patient has been skipped by correlate parent's alias substitution; but given that Task's Patient is optional we should reserve theleft join
fromTask
toPatient
.The fix in this PR is to create the following jpasql instead:
The basic idea is to generate new alias for correlated root and add
newAlias = oldAlias
to theWHERE
jpasql clause, thus reserving theLEFT JOIN
semantic of the correlated root in subquery.However, the old pattern still remains for performance reason and the above changes only apply when
LEFT JOIN
is involved.