Kenny Moens (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea94bd...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjZlOTVjYjMy...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-13988?atlOrigin=eyJpIjoiNjZlOT...
) HHH-13988 (
https://hibernate.atlassian.net/browse/HHH-13988?atlOrigin=eyJpIjoiNjZlOT...
) Entity which refers to itself: invalid update statement created (
https://hibernate.atlassian.net/browse/HHH-13988?atlOrigin=eyJpIjoiNjZlOT...
)
Change By: Kenny Moens (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea94bd...
)
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:
{code :java }
update OpdrachtPlan o set o.plan.id = :newPlanId where o.plan.id = :planId and
o.isProCalc = false and o.maand >= :datum
{code}
Hibernate 5.4.14 generates the following (invalid) SQL statement for this query:
{code:sql}
update
SDOPDR cross
join
set
PKSDOPDRREF=?
where
(
SDOPDRPROCALC = 0
)
and PKSDOPDRREF=?
and SDOPDRPROCALC=false
and SDOPDRMND>=?
{code}
In the previous Hibernate 5.3.16, we got the following SQL statement, which works
correctly:
{code:sql}
update
SDOPDR
set
FKSDOPDR_OPDRREF_MASTER=?
where
(
SDOPDRPROCALC = 0
)
and FKSDOPDR_OPDRREF_MASTER=?
and SDOPDRPROCALC=false
and SDOPDRMND>=?
{code}
Based on my investigation, this issue appears to be introduced by multiple changes:
[
https://hibernate.atlassian.net/browse/ HHH-13875 |https :
//hibernate.atlassian.net/browse/HHH-13875|smart-link] 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 [ HHH-12842 ] and [ HHH-12775 ] 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-test-case-templates.zip]
(
https://hibernate.atlassian.net/browse/HHH-13988#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-13988#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:e06514a )