[JIRA] (HHH-16505) interpretation of "bare" alias reference in HQL
by Gavin King (JIRA)
Gavin King ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzM4N2VhZTk3... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16505?atlOrigin=eyJpIjoiNzM4N2... ) HHH-16505 ( https://hibernate.atlassian.net/browse/HHH-16505?atlOrigin=eyJpIjoiNzM4N2... ) interpretation of "bare" alias reference in HQL ( https://hibernate.atlassian.net/browse/HHH-16505?atlOrigin=eyJpIjoiNzM4N2... )
Issue Type: Bug Affects Versions: 6.2.1 Assignee: Unassigned Components: query-hql Created: 24/Apr/2023 03:43 AM Priority: Major Reporter: Gavin King ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
So here’s a very interesting one that came up here: https://stackoverflow.com/questions/76073151/incorrect-sql-where-clause-g...
Please ignore the actual query that the user displays, as you can see in my answer, it’s not a reasonable query to write.
Instead just focus on the change in behavior.
Given the query:
SELECT book
FROM Book book
LEFT JOIN book.author a
WHERE a is not null
We optimize this to the SQL:
select
b1_0.id,
b1_0.author_id,
b1_0.publishingHouse_id,
b1_0.title
from
Book b1_0
where
b1_0.author_id is not null
which is frankly pretty awesome.
But now consider this variation:
SELECT book
FROM Book book
LEFT JOIN book.author a WITH a.alive = true
WHERE a is not null
Now the generated SQL is:
select
b1_0.id,
b1_0.author_id,
b1_0.publishingHouse_id,
b1_0.title
from
Book b1_0
left join
Author a1_0
on a1_0.id=b1_0.author_id
and a1_0.alive= true
where
b1_0.author_id is not null
and, after reflection, I’m inclined to agree with the user that this is not quite correct.
I think they’re probably right to say that a is not null should translate to {{a1_0.id is not null}}in this particular case.
( https://hibernate.atlassian.net/browse/HHH-16505#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16505#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100223- sha1:77dfe11 )
2 years, 5 months