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).
if ( session.getCacheMode().isGetEnabled() && persister.canUseReferenceCacheEntries() ) {
final EntityDataAccess cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(
key.getIdentifier(),
persister,
session.getFactory(),
session.getTenantIdentifier()
if ( cache != null ) {
final Object ck = cache.generateCacheKey(
key.getIdentifier(),
persister,
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 );
if ( cachedEntry != null ) {
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure( cachedEntry, factory );
return ( (ReferenceCacheEntryImpl) entry ).getReference();
return ( (ReferenceCacheEntryImpl) entry ).getReference();
}
}
}