HHH-18631 AssertionError when loading an entity after removing another, associated entity

This commit is contained in:
Andrea Boriero 2024-09-18 17:35:01 +02:00 committed by Andrea Boriero
parent dd9f79096f
commit 34b479a719
1 changed files with 9 additions and 7 deletions

View File

@ -85,7 +85,6 @@ import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCH
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
import static org.hibernate.internal.util.NullnessUtil.castNonNull; import static org.hibernate.internal.util.NullnessUtil.castNonNull;
import static org.hibernate.metamodel.mapping.ForeignKeyDescriptor.Nature.TARGET;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
/** /**
@ -931,12 +930,15 @@ public class EntityInitializerImpl extends AbstractInitializer<EntityInitializer
); );
data.entityHolder = persistenceContext.getEntityHolder( data.entityKey ); data.entityHolder = persistenceContext.getEntityHolder( data.entityKey );
if ( data.entityHolder == null ) { if ( data.entityHolder == null ) {
// Entity was most probably removed in the same session without setting the reference to null // Entity was most probably removed in the same session without setting this association to null.
resolveKey( data ); // Since this load request can happen through `find()` which doesn't auto-flush on association joins,
assert data.getState() == State.MISSING; // the entity must be fully initialized, even if it is removed already
assert referencedModelPart instanceof ToOneAttributeMapping data.entityHolder = persistenceContext.claimEntityHolderIfPossible(
&& ( (ToOneAttributeMapping) referencedModelPart ).getSideNature() == TARGET; data.entityKey,
return; data.entityInstanceForNotify,
rowProcessingState.getJdbcValuesSourceProcessingState(),
this
);
} }
if ( data.concreteDescriptor.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() if ( data.concreteDescriptor.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading()
&& isPersistentAttributeInterceptable( data.entityInstanceForNotify ) && isPersistentAttributeInterceptable( data.entityInstanceForNotify )