Skip to content

Commit 52e3dfc

Browse files
committed
[#1770] Fix iniailizing field after fetching it
1 parent 3f252df commit 52e3dfc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.hibernate.UnknownEntityTypeException;
1919
import org.hibernate.UnresolvableObjectException;
2020
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
21+
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
2122
import org.hibernate.collection.spi.PersistentCollection;
2223
import org.hibernate.dialect.Dialect;
2324
import org.hibernate.reactive.engine.impl.ReactivePersistenceContextAdapter;
@@ -359,8 +360,20 @@ else if ( isPersistentAttributeInterceptable( association ) ) {
359360

360361
@Override
361362
public <E, T> CompletionStage<T> reactiveFetch(E entity, Attribute<E, T> field) {
362-
return ( (ReactiveEntityPersister) getEntityPersister( null, entity ) )
363-
.reactiveInitializeLazyProperty( field, entity, this );
363+
final ReactiveEntityPersister entityPersister = (ReactiveEntityPersister) getEntityPersister( null, entity );
364+
LazyAttributeLoadingInterceptor lazyAttributeLoadingInterceptor = entityPersister.getBytecodeEnhancementMetadata()
365+
.extractInterceptor( entity );
366+
final String attributeName = field.getName();
367+
if ( !lazyAttributeLoadingInterceptor.isAttributeLoaded( attributeName ) ) {
368+
return ( (CompletionStage<T>) lazyAttributeLoadingInterceptor.fetchAttribute( entity, field.getName() ) )
369+
.thenApply( value -> {
370+
lazyAttributeLoadingInterceptor.attributeInitialized( attributeName );
371+
return value;
372+
} );
373+
}
374+
else {
375+
return completedFuture( (T) entityPersister.getPropertyValue( entity, attributeName ) );
376+
}
364377
}
365378

366379
@Override

0 commit comments

Comments
 (0)