HHH-18212 Handle entity in existing state removed from current session

This commit is contained in:
Marco Belladelli 2024-06-03 17:30:22 +02:00
parent 46e0f43567
commit c5cbe20bd1
1 changed files with 9 additions and 0 deletions

View File

@ -81,6 +81,7 @@ import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCH
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
import static org.hibernate.internal.log.LoggingHelper.toLoggableString;
import static org.hibernate.metamodel.mapping.ForeignKeyDescriptor.Nature.TARGET;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
/**
@ -619,6 +620,14 @@ public class EntityInitializerImpl extends AbstractInitializer implements Entity
concreteDescriptor.getIdentifier( entityInstance, session )
);
entityHolder = session.getPersistenceContextInternal().getEntityHolder( entityKey );
if ( entityHolder == null ) {
// Entity was most probably removed in the same session
resolveKey();
assert state == State.MISSING;
assert referencedModelPart instanceof ToOneAttributeMapping
&& ( (ToOneAttributeMapping) referencedModelPart ).getSideNature() == TARGET;
return;
}
// If the entity initializer is null, we know the entity is fully initialized,
// otherwise it will be initialized by some other initializer
state = entityHolder.getEntityInitializer() == null ? State.INITIALIZED : State.RESOLVED;