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,6 +1730,7 @@ 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();
if ( cache != null ) {
final Object ck = cache.generateCacheKey(
key.getIdentifier(),
persister,
@ -1738,10 +1739,14 @@ public abstract class Loader {
);
final Object cachedEntry = CacheHelper.fromSharedCache( session, ck, cache );
if ( cachedEntry != null ) {
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure( cachedEntry, factory );
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure(
cachedEntry,
factory
);
return ( (ReferenceCacheEntryImpl) entry ).getReference();
}
}
}
final Object object;
if ( optionalObjectKey != null && key.equals( optionalObjectKey ) ) {