Skip to content

Commit

Permalink
HHH-11766 : Accessing lazy basic property on entity loaded from 2nd l…
Browse files Browse the repository at this point in the history
…evel cache throws exception

(cherry picked from commit 01ba7d9)
  • Loading branch information
gbadner committed Apr 20, 2018
1 parent 180eca3 commit e8929e6
Showing 1 changed file with 24 additions and 10 deletions.
Expand Up @@ -992,10 +992,13 @@ public Object initializeLazyProperty(String fieldName, Object entity, SharedSess
if ( ce != null ) {
final CacheEntry cacheEntry = (CacheEntry) getCacheEntryStructure().destructure( ce, factory );
final Object initializedValue = initializeLazyPropertiesFromCache( fieldName, entity, session, entry, cacheEntry );
interceptor.attributeInitialized( fieldName );
if (initializedValue != LazyPropertyInitializer.UNFETCHED_PROPERTY) {
// The following should be redundant, since the setter should have set this already.
// interceptor.attributeInitialized(fieldName);

// NOTE EARLY EXIT!!!
return initializedValue;
// NOTE EARLY EXIT!!!
return initializedValue;
}
}
}

Expand Down Expand Up @@ -1150,13 +1153,24 @@ private Object initializeLazyPropertiesFromCache(
Serializable[] disassembledValues = cacheEntry.getDisassembledState();
final Object[] snapshot = entry.getLoadedState();
for ( int j = 0; j < lazyPropertyNames.length; j++ ) {
final Object propValue = lazyPropertyTypes[j].assemble(
disassembledValues[lazyPropertyNumbers[j]],
session,
entity
);
if ( initializeLazyProperty( fieldName, entity, session, snapshot, j, propValue ) ) {
result = propValue;
final Serializable cachedValue = disassembledValues[lazyPropertyNumbers[j]];
final Type lazyPropertyType = lazyPropertyTypes[j];
final String propertyName = lazyPropertyNames[j];
if (cachedValue == LazyPropertyInitializer.UNFETCHED_PROPERTY) {
if (fieldName.equals(propertyName)) {
result = LazyPropertyInitializer.UNFETCHED_PROPERTY;
}
// don't try to initialize the unfetched property
}
else {
final Object propValue = lazyPropertyType.assemble(
cachedValue,
session,
entity
);
if ( initializeLazyProperty( fieldName, entity, session, snapshot, j, propValue ) ) {
result = propValue;
}
}
}

Expand Down

0 comments on commit e8929e6

Please sign in to comment.