Koen Serneels (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjhjYzllNTRm...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-14054?atlOrigin=eyJpIjoiYjhjYz...
) HHH-14054 (
https://hibernate.atlassian.net/browse/HHH-14054?atlOrigin=eyJpIjoiYjhjYz...
) Hibernate insert/update ordering wrt unique constraints (
https://hibernate.atlassian.net/browse/HHH-14054?atlOrigin=eyJpIjoiYjhjYz...
)
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%...
)
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-un...
, 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=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-14054#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#100127- sha1:6728f9f )