HHH-15840 HibernateException: Found shared references to a collection when loading a collection from the cache

This commit is contained in:
Andrea Boriero 2022-12-10 11:17:38 +01:00 committed by Andrea Boriero
parent 7ec8668734
commit 733e6cafdb
1 changed files with 6 additions and 1 deletions

View File

@ -281,7 +281,7 @@ public class DefaultLoadEventListener implements LoadEventListener {
private static boolean hasBytecodeProxy(EntityPersister persister, LoadType options) {
return options.isAllowProxyCreation()
&& persister.getEntityMetamodel().getBytecodeEnhancementMetadata().isEnhancedForLazyLoading();
&& persister.getEntityPersister().getBytecodeEnhancementMetadata().isEnhancedForLazyLoading();
}
private static Object loadWithProxyFactory(LoadEvent event, EntityPersister persister, EntityKey keyToLoad) {
@ -342,6 +342,11 @@ public class DefaultLoadEventListener implements LoadEventListener {
}
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(),