[hibernate-issues] [JIRA] (HHH-14054) Hibernate insert/update ordering wrt unique constraints

Koen Serneels (JIRA) jira at hibernate.atlassian.net
Tue Jun 2 03:05:03 EDT 2020


Koen Serneels ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A956c77bd-dde9-4e6d-aafd-30082b747b74 ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjhjYzllNTRmMmE3NGM4ZGIwYmM1YjU0NmU1YzdiY2YiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14054?atlOrigin=eyJpIjoiYjhjYzllNTRmMmE3NGM4ZGIwYmM1YjU0NmU1YzdiY2YiLCJwIjoiaiJ9 ) HHH-14054 ( https://hibernate.atlassian.net/browse/HHH-14054?atlOrigin=eyJpIjoiYjhjYzllNTRmMmE3NGM4ZGIwYmM1YjU0NmU1YzdiY2YiLCJwIjoiaiJ9 ) Hibernate insert/update ordering wrt unique constraints ( https://hibernate.atlassian.net/browse/HHH-14054?atlOrigin=eyJpIjoiYjhjYzllNTRmMmE3NGM4ZGIwYmM1YjU0NmU1YzdiY2YiLCJwIjoiaiJ9 )

Issue Type: Bug Affects Versions: 5.4.17 Assignee: Unassigned Components: hibernate-core Created: 02/Jun/2020 00:05 AM Priority: Major Reporter: Koen Serneels ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A956c77bd-dde9-4e6d-aafd-30082b747b74 )

Hi. In the example created for this question (please see: https://github.com/koen-serneels/hibernate-uc-violation ) is an entity with a single property ‘value’ and unique constraint. Initially there is an existing instance with it’s property ‘value’ equal to ‘val1’. When we now do following within the same transaction:

* change the value on the existing entity from “val1” to “val2”
* add a new entity with “val1”

We get a ConstraintViolationException because Hibernate is executing the insert before the update. Two questions about this behavior

* Is this actually expected knowing that Hibernate knows about the unique constraint and that it would make more sense to perform the insert after the update?
* Is there a more elegant way to deal with this than performing manual flushes as illustrated by the test
case?

Btw; I posted this first on the forum ( https://discourse.hibernate.org/t/hibernate-insert-update-ordering-wrt-unique-constraints/4201 , but in absence of any response I started thinking this might be a bug. Thanks!

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

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#100127- sha1:6728f9f )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200602/f233ae64/attachment.html 


More information about the hibernate-issues mailing list