HHH-16613 @Lazy @ManyToOne @Cacheable association is retrieved as initialized

This commit is contained in:
Andrea Boriero 2023-05-31 12:53:16 +02:00 committed by Andrea Boriero
parent f6ec141b47
commit 7157899079
1 changed files with 1 additions and 22 deletions

View File

@ -279,7 +279,7 @@ public class DefaultLoadEventListener implements LoadEventListener {
}
else if ( options.isAllowProxyCreation() ) {
// return a new proxy
return proxyOrCached( event, persister, keyToLoad, options );
return createProxyIfNecessary( event, persister, keyToLoad, options );
}
else {
// return a newly loaded object
@ -349,27 +349,6 @@ public class DefaultLoadEventListener implements LoadEventListener {
return createProxy( event, persister, keyToLoad );
}
private static Object proxyOrCached(LoadEvent event, EntityPersister persister, EntityKey keyToLoad, LoadType options) {
final PersistenceContext persistenceContext = event.getSession().getPersistenceContext();
final Object existing = persistenceContext.getEntity( keyToLoad );
if ( existing != null ) {
return options.isCheckDeleted() && wasDeleted( persistenceContext, existing ) ? null : existing;
}
if ( persister.hasSubclasses() ) {
final Object cachedEntity = CacheEntityLoaderHelper.INSTANCE.loadFromSecondLevelCache(
event.getSession(),
null,
LockMode.NONE,
persister,
keyToLoad
);
if ( cachedEntity != null ) {
return cachedEntity;
}
}
return createProxyIfNecessary( event, persister, keyToLoad, options );
}
/**
* Given a proxy, initialize it and/or narrow it provided either
* is necessary.