HHH-15218 @OptimisticLocking(DIRTY) leads to wrong query during delete of circular reference
This commit is contained in:
parent
0a013ed8a4
commit
06e44f2adb
|
@ -30,6 +30,7 @@ import org.hibernate.metamodel.mapping.NaturalIdMapping;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.stat.internal.StatsHelper;
|
import org.hibernate.stat.internal.StatsHelper;
|
||||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||||
|
import org.hibernate.tuple.entity.EntityMetamodel;
|
||||||
import org.hibernate.type.TypeHelper;
|
import org.hibernate.type.TypeHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,6 +202,18 @@ public class EntityUpdateAction extends EntityAction {
|
||||||
entry.postUpdate( instance, state, nextVersion );
|
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();
|
final StatisticsImplementor statistics = factory.getStatistics();
|
||||||
if ( persister.canWriteToCache() ) {
|
if ( persister.canWriteToCache() ) {
|
||||||
if ( persister.isCacheInvalidationRequired() || entry.getStatus() != Status.MANAGED ) {
|
if ( persister.isCacheInvalidationRequired() || entry.getStatus() != Status.MANAGED ) {
|
||||||
|
|
Loading…
Reference in New Issue