HHH-13665 selecting an Entity annotated with @Immutalbe but not with @Cachable causes a NPE when use_reference_entries is enabled

This commit is contained in:
Andrea Boriero 2019-10-14 16:31:21 +01:00 committed by Sanne Grinovero
parent 8d9eb04d16
commit c392d03bf1
1 changed files with 14 additions and 9 deletions

View File

@ -1730,16 +1730,21 @@ public abstract class Loader {
// see if the entity defines reference caching, and if so use the cached reference (if one). // see if the entity defines reference caching, and if so use the cached reference (if one).
if ( session.getCacheMode().isGetEnabled() && persister.canUseReferenceCacheEntries() ) { if ( session.getCacheMode().isGetEnabled() && persister.canUseReferenceCacheEntries() ) {
final EntityDataAccess cache = persister.getCacheAccessStrategy(); final EntityDataAccess cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey( if ( cache != null ) {
key.getIdentifier(), final Object ck = cache.generateCacheKey(
persister, key.getIdentifier(),
session.getFactory(), persister,
session.getTenantIdentifier() session.getFactory(),
session.getTenantIdentifier()
);
final Object cachedEntry = CacheHelper.fromSharedCache( session, ck, cache );
if ( cachedEntry != null ) {
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure(
cachedEntry,
factory
); );
final Object cachedEntry = CacheHelper.fromSharedCache( session, ck, cache ); return ( (ReferenceCacheEntryImpl) entry ).getReference();
if ( cachedEntry != null ) { }
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure( cachedEntry, factory );
return ( (ReferenceCacheEntryImpl) entry ).getReference();
} }
} }