So here’s a very interesting one that came up here: https://stackoverflow.com/questions/76073151/incorrect-sql-where-clause-generated-from-hql-since-hibernate-6-using-test-on-le 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. |