SQL query accesses non-existing alias in update/delete
Description
Activity
Show:

Christian Beikov April 17, 2024 at 11:25 AM
Joins are now supported in DML queries in ORM 6.5 and the issue of referring to non-existing aliases was certainly fixed at least in ORM 6.4
Marco Belladelli May 30, 2023 at 12:09 PM
Hello , the unexpected alias is used because your query would need an implicit join (PrivateSubData
with PrivateData
) to use the person_id
column. Joins are currently not supported for mutation queries in Hibernate 6. I also tested your example with Hibernate 5.6 since you reported it was working but it did not work for me.
One way to work around this would be using a subquery, something like:
With the update from hibernate 5.6 to 6.2 some of our update and delete queries cause invalid SQL to be generated. In all cases there’s an alias used in the where clause which isn’t declared. This occurs in cases the query contains a condition which refers to a relation of the entity to update/delete.
The JPQL query
is translated to SQL as
We were able to create a reproducer with 3 entities. In our production code, this also occurs in cases with only 2 entites which do not require any join or inner select. We could not reproduce this case in a simple code base.
A reproducer can be found at