HHH-15218 @OptimisticLocking(DIRTY) leads to wrong query during delete of circular reference
This commit is contained in:
parent
3f5b12c9e5
commit
6b4ac625e1
|
@ -32,6 +32,7 @@ import org.hibernate.event.spi.PreUpdateEventListener;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
@ -239,6 +240,18 @@ public class EntityUpdateAction extends EntityAction {
|
|||
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 ) {
|
||||
|
|
Loading…
Reference in New Issue