We recently did an upgrade from Hibernate 5.3.16 to Hibernate 5.4.14 inside one of our applications.
One of our enitity has a foreign key relationship inside its own table, and additionally uses discriminators for that table.
Basically we execute the following update statement:
Hibernate 5.4.14 generates the following (invalid) SQL statement for this query:
In the previous Hibernate 5.3.16, we got the following SQL statement, which works correctly:
Based on my investigation, this issue appears to be introduced by multiple changes:
the addition of the isNull check inside dereferenceEntity causes that we don't get inside the isPropertyEmbeddedInJoinProperties method anymore, which is necessary. This would have been sufficient if we named our primary keys id instead of objectId. As part of our investigation we then downgraded to 5.4.12 which didn't contain this patch.
The combination of and prevents that the objectId path is properly registered inside AbstractPropertyMapping.initIdentifierPropertyPaths().
As an attachment, you can find a number of traces of the AST of SQL, HBM, loggings of the mapping and the SQL statement itself.
I don't know what would be the best solution to solve this bug, I did however make a stripped down test case to reproduce this:
Hibernate 5.4.14, AdoptOpenJDK 8u252, Windows, H2 + HSQLDB
We had to downgrade to Hibernate 5.3, hence the blocking state.