Christian Beikov (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMTJlZWM2NjVj...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16690?atlOrigin=eyJpIjoiMTJlZW...
) HHH-16690 (
https://hibernate.atlassian.net/browse/HHH-16690?atlOrigin=eyJpIjoiMTJlZW...
) Re-saving deleted object leads to constraint violation when unloaded delete happened (
https://hibernate.atlassian.net/browse/HHH-16690?atlOrigin=eyJpIjoiMTJlZW...
)
Issue Type: Bug Affects Versions: 6.2.3 Assignee: Unassigned Components: hibernate-core
Created: 25/May/2023 01:20 AM Priority: Major Reporter: Christian Beikov (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
We have plenty of code that checks EntityEntry.getStatus() == DELETED , but with the
unloaded delete optimization we don’t create entity entries anymore.
Since PersistenceContext contains deletedUnloadedEntityKeys though, we could still make
this work but have to review all code paths that try to handle re-saving.
Imagine a model like this
@Entity
public class EntityHolder {
@Id
Long id;
@OneToOne
SubEntity sub;
}
@Entity
public class SubEntity {
@Id
Long id;
String name;
}
When doing the following
em.remove(em.getReference(SubEntity.class, 1L));
em.persist(new SubEntity(1L, "re-saved"));
previous Hibernate versions forced a flush due to the re-saving. Current Hibernate doesn’t
do that, because there is no entity entry with status DELETED anymore that would lead to
this code. The entry is missing because the remove operation used the optimized unloaded
deletion.
The effect of this is, that the unique key constraint for EntityHolder#sub will now start
to produce constraint violation exceptions.
(
https://hibernate.atlassian.net/browse/HHH-16690#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16690#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#100225- sha1:0428b75 )