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 3f5b12c commit 6b4ac62
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 @@ -239,6 +240,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 6b4ac62

Please sign in to comment.