|
18 | 18 | import org.hibernate.UnknownEntityTypeException; |
19 | 19 | import org.hibernate.UnresolvableObjectException; |
20 | 20 | import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor; |
| 21 | +import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor; |
21 | 22 | import org.hibernate.collection.spi.PersistentCollection; |
22 | 23 | import org.hibernate.dialect.Dialect; |
23 | 24 | import org.hibernate.engine.internal.ReactivePersistenceContextAdapter; |
@@ -359,8 +360,20 @@ else if ( isPersistentAttributeInterceptable( association ) ) { |
359 | 360 |
|
360 | 361 | @Override |
361 | 362 | 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 | + } |
364 | 377 | } |
365 | 378 |
|
366 | 379 | @Override |
|
0 commit comments