Skip to content

Commit e609555

Browse files
committed
HHH-13377 Lazy loaded properties of bytecode enhanced entity are left stale after refresh of entity
1 parent 9bcb330 commit e609555

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributeLoadingInterceptor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,8 @@ public void addLazyFieldByGraph(String fieldName) {
198198
}
199199
mutableLazyFields.add( fieldName );
200200
}
201+
202+
public void clearInitializedLazyFields() {
203+
initializedLazyFields = null;
204+
}
201205
}

hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.hibernate.NonUniqueObjectException;
1111
import org.hibernate.TransientObjectException;
1212
import org.hibernate.UnresolvableObjectException;
13+
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
14+
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
1315
import org.hibernate.cache.spi.access.CollectionDataAccess;
1416
import org.hibernate.cache.spi.access.EntityDataAccess;
1517
import org.hibernate.cache.spi.access.SoftLock;
@@ -189,6 +191,14 @@ private static void refresh(
189191
EntityEntry entry,
190192
Object id,
191193
PersistenceContext persistenceContext) {
194+
final BytecodeEnhancementMetadata instrumentationMetadata = persister.getInstrumentationMetadata();
195+
if ( object != null && instrumentationMetadata.isEnhancedForLazyLoading() ) {
196+
final LazyAttributeLoadingInterceptor interceptor = instrumentationMetadata.extractInterceptor( object );
197+
if ( interceptor != null ) {
198+
// The list of initialized lazy fields have to be cleared in order to refresh them from the database.
199+
interceptor.clearInitializedLazyFields();
200+
}
201+
}
192202

193203
final Object result = source.getLoadQueryInfluencers().fromInternalFetchProfile(
194204
CascadingFetchProfile.REFRESH,

0 commit comments

Comments
 (0)