HHH-11147 Fix initializing an entity that does not exist
This commit is contained in:
parent
ac7fcbb465
commit
663bbc81d7
|
@ -75,6 +75,7 @@ import org.hibernate.engine.spi.EntityKey;
|
|||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||
import org.hibernate.engine.spi.LoadQueryInfluencers;
|
||||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
|
@ -4311,16 +4312,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
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue