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 0bc1d5a88c
commit beb4c3891c
1 changed files with 15 additions and 3 deletions

View File

@ -4320,16 +4320,28 @@ public abstract class AbstractEntityPersister
if ( currentInterceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
final EnhancementAsProxyLazinessInterceptor proxyInterceptor = (EnhancementAsProxyLazinessInterceptor) currentInterceptor;
readLockLoader.load(
proxyInterceptor.getEntityKey().getIdentifier(),
final EntityKey entityKey = proxyInterceptor.getEntityKey();
final Serializable identifier = entityKey.getIdentifier();
final Object loaded = readLockLoader.load(
identifier,
entity,
session,
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(
entity,
proxyInterceptor.getEntityKey().getIdentifier(),
identifier,
session
);