[hibernate-issues] [JIRA] (HHH-13988) Entity which refers to itself: invalid update statement created

Kenny Moens (JIRA) jira at hibernate.atlassian.net
Wed Apr 29 05:58:53 EDT 2020


Kenny Moens ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea94bd49ce9ee0b894350db ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNmVhZGM2MTFhNGE3NDM4ZTgxN2JkNWJkZWY2YTNkM2IiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13988?atlOrigin=eyJpIjoiNmVhZGM2MTFhNGE3NDM4ZTgxN2JkNWJkZWY2YTNkM2IiLCJwIjoiaiJ9 ) HHH-13988 ( https://hibernate.atlassian.net/browse/HHH-13988?atlOrigin=eyJpIjoiNmVhZGM2MTFhNGE3NDM4ZTgxN2JkNWJkZWY2YTNkM2IiLCJwIjoiaiJ9 ) Entity which refers to itself: invalid update statement created ( https://hibernate.atlassian.net/browse/HHH-13988?atlOrigin=eyJpIjoiNmVhZGM2MTFhNGE3NDM4ZTgxN2JkNWJkZWY2YTNkM2IiLCJwIjoiaiJ9 )

Issue Type: Bug Affects Versions: 5.4.0, 5.4.14 Assignee: Unassigned Attachments: hibernate-test-case-templates.zip, hql ast - HB5.3.txt, hql ast - HB5.4.txt, hql to sql - HB5.3.txt, hql to sql - HB5.4.txt, sql ast - HB5.3.txt, sql ast - HB5.4.txt, sql statement - HB5.3.txt, sql statement - HB5.4.txt Created: 29/Apr/2020 02:58 AM Environment: Hibernate 5.4.14, AdoptOpenJDK 8u252, Windows, H2 + HSQLDB Priority: Major Reporter: Kenny Moens ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea94bd49ce9ee0b894350db )

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:

update OpdrachtPlan o  set o.plan.id = :newPlanId  where o.plan.id = :planId  and o.isProCalc = false  and o.maand >= :datum

Hibernate 5.4.14 generates the following (invalid) SQL statement for this query:

   update
       SDOPDR cross 
   join
       
   set
       PKSDOPDRREF=? 
   where
       (
           SDOPDRPROCALC = 0
       ) 
       and PKSDOPDRREF=? 
       and SDOPDRPROCALC= false 
       and SDOPDRMND>=?

In the previous Hibernate 5.3.16, we got the following SQL statement, which works correctly:

   update
       SDOPDR 
   set
       FKSDOPDR_OPDRREF_MASTER=? 
   where
       (
           SDOPDRPROCALC = 0
       ) 
       and FKSDOPDR_OPDRREF_MASTER=? 
       and SDOPDRPROCALC= false 
       and SDOPDRMND>=?

Based on my investigation, this issue appears to be introduced by multiple changes:

HHH-13875: 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 ( https://hibernate.atlassian.net/browse/HHH-12842 ) Closed and HHH-12775 ( https://hibernate.atlassian.net/browse/HHH-12775 ) Closed 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/secure/attachment/49661/49661_hibernate-test-case-templates.zip )

( https://hibernate.atlassian.net/browse/HHH-13988#add-comment?atlOrigin=eyJpIjoiNmVhZGM2MTFhNGE3NDM4ZTgxN2JkNWJkZWY2YTNkM2IiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13988#add-comment?atlOrigin=eyJpIjoiNmVhZGM2MTFhNGE3NDM4ZTgxN2JkNWJkZWY2YTNkM2IiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:e06514a )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200429/e44b906b/attachment.html 


More information about the hibernate-issues mailing list