HHH-11147 Fix initializing an entity that does not exist

This commit is contained in:
Andrea Boriero 2019-06-27 16:59:26 +01:00 committed by Sanne Grinovero
parent ac7fcbb465
commit 663bbc81d7
1 changed files with 16 additions and 3 deletions

View File

@ -75,6 +75,7 @@ import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper; import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper;
import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor; import org.hibernate.engine.spi.PersistentAttributeInterceptor;
@ -4311,16 +4312,28 @@ public abstract class AbstractEntityPersister
if ( currentInterceptor instanceof EnhancementAsProxyLazinessInterceptor ) { if ( currentInterceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
final EnhancementAsProxyLazinessInterceptor proxyInterceptor = (EnhancementAsProxyLazinessInterceptor) currentInterceptor; final EnhancementAsProxyLazinessInterceptor proxyInterceptor = (EnhancementAsProxyLazinessInterceptor) currentInterceptor;
readLockLoader.load( final EntityKey entityKey = proxyInterceptor.getEntityKey();
proxyInterceptor.getEntityKey().getIdentifier(), final Serializable identifier = entityKey.getIdentifier();
final Object loaded = readLockLoader.load(
identifier,
entity, entity,
session, session,
LockOptions.READ LockOptions.READ
); );
if ( loaded == null ) {
final PersistenceContext persistenceContext = session.getPersistenceContext();
persistenceContext.removeEntry( entity );
persistenceContext.removeEntity( entityKey );
session.getFactory().getEntityNotFoundDelegate().handleEntityNotFound(
entityKey.getEntityName(),
identifier
);
}
final LazyAttributeLoadingInterceptor interceptor = enhancementMetadata.injectInterceptor( final LazyAttributeLoadingInterceptor interceptor = enhancementMetadata.injectInterceptor(
entity, entity,
proxyInterceptor.getEntityKey().getIdentifier(), identifier,
session session
); );