Skip to content

Commit

Permalink
HHH-15218 @OptimisticLocking(DIRTY) leads to wrong query during delet…
Browse files Browse the repository at this point in the history
…e of circular reference
  • Loading branch information
dreab8 authored and Sanne committed Jul 6, 2022
1 parent 0a013ed commit 06e44f2
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -30,6 +30,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.stat.internal.StatsHelper;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.type.TypeHelper;

/**
Expand Down Expand Up @@ -201,6 +202,18 @@ public void execute() throws HibernateException {
entry.postUpdate( instance, state, nextVersion );
}

if ( entry.getStatus() == Status.DELETED ) {
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
final boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned()
&& entityMetamodel.getOptimisticLockStyle().isAllOrDirty();
if ( isImpliedOptimisticLocking && entry.getLoadedState() != null ) {
// The entity will be deleted and because we are going to create a delete statement that uses
// all the state values in the where clause, the entry state needs to be updated otherwise the statement execution will
// not delete any row (see HHH-15218).
entry.postUpdate( instance, state, nextVersion );
}
}

final StatisticsImplementor statistics = factory.getStatistics();
if ( persister.canWriteToCache() ) {
if ( persister.isCacheInvalidationRequired() || entry.getStatus() != Status.MANAGED ) {
Expand Down

0 comments on commit 06e44f2

Please sign in to comment.