search second level cache if proxy entity metamodel has subclasses

This commit is contained in:
Andrea Boriero 2021-10-18 19:16:46 +02:00
parent 1ffa1347a3
commit 6ffcee44a6
1 changed files with 24 additions and 0 deletions

View File

@ -288,6 +288,17 @@ public class DefaultLoadEventListener implements LoadEventListener {
// specialized handling for entities with subclasses with a HibernateProxy factory
if ( entityMetamodel.hasSubclasses() ) {
final Object cachedEntity = CacheEntityLoaderHelper.INSTANCE.loadFromSecondLevelCache(
session,
null,
LockMode.NONE,
persister,
keyToLoad
);
if ( cachedEntity != null ) {
return cachedEntity;
}
// entities with subclasses that define a ProxyFactory can create a HibernateProxy
return createProxy( event, persister, keyToLoad, persistenceContext );
}
@ -314,6 +325,19 @@ public class DefaultLoadEventListener implements LoadEventListener {
}
if ( options.isAllowProxyCreation() ) {
if ( entityMetamodel.hasSubclasses() ) {
final Object cachedEntity = CacheEntityLoaderHelper.INSTANCE.loadFromSecondLevelCache(
session,
null,
LockMode.NONE,
persister,
keyToLoad
);
if ( cachedEntity != null ) {
return cachedEntity;
}
}
return createProxyIfNecessary( event, persister, keyToLoad, options, persistenceContext );
}
}