diff --git a/build.gradle b/build.gradle index 1ac93d309..6893e448a 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ version = projectVersion // ./gradlew clean build -PhibernateOrmVersion=5.6.15-SNAPSHOT ext { if ( !project.hasProperty('hibernateOrmVersion') ) { - hibernateOrmVersion = '6.4.0.Final' + hibernateOrmVersion = '6.4.1.Final' } if ( !project.hasProperty( 'hibernateOrmGradlePluginVersion' ) ) { // Same as ORM as default diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveLoadEventListener.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveLoadEventListener.java index ae79148d1..e84387950 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveLoadEventListener.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveLoadEventListener.java @@ -380,8 +380,6 @@ private CompletionStage loadWithRegularProxy(LoadEvent event, EntityPers return narrowedProxy( event, persister, keyToLoad, options, proxy ); } else if ( options.isAllowProxyCreation() ) { - // return a new proxy - // ORM calls DefaultLoadEventListener#proxyOrCache return completedFuture( proxyOrCached( event, persister, keyToLoad, options ) ); } else { diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactivePostLoadEventListener.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactivePostLoadEventListener.java index 49c62c182..053c8465f 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactivePostLoadEventListener.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactivePostLoadEventListener.java @@ -43,21 +43,24 @@ public void onPostLoad(PostLoadEvent event) { callbackRegistry.postLoad( entity ); final EventSource session = event.getSession(); - final EntityEntry entry = session.getPersistenceContextInternal().getEntry( entity ); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( entity ); if ( entry == null ) { throw new AssertionFailure( "possible non-threadsafe access to the session" ); } - final ReactiveActionQueue actionQueue = ((ReactiveSession) session).getReactiveActionQueue(); + final ReactiveActionQueue actionQueue = ( (ReactiveSession) session ).getReactiveActionQueue(); switch ( entry.getLockMode() ) { -// case PESSIMISTIC_FORCE_INCREMENT: - // This case is handled by DefaultReactiveLoadEventListener + case PESSIMISTIC_FORCE_INCREMENT: + // This case is handled by DefaultReactiveLoadEventListener + break; case OPTIMISTIC_FORCE_INCREMENT: actionQueue.registerProcess( new ReactiveEntityIncrementVersionProcess( entity ) ); break; case OPTIMISTIC: actionQueue.registerProcess( new ReactiveEntityVerifyVersionProcess( entity ) ); break; + default: + // Nothing to do } } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/ReactiveAbstractEntityInitializer.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/ReactiveAbstractEntityInitializer.java index e470f7b22..59466966c 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/ReactiveAbstractEntityInitializer.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/ReactiveAbstractEntityInitializer.java @@ -87,7 +87,23 @@ public CompletionStage reactiveInitializeInstance(ReactiveRowProcessingSta return voidFuture() .thenCompose( v -> { if ( lazyInitializer != null ) { - return lazyInitialize( rowProcessingState, lazyInitializer ); + final SharedSessionContractImplementor session = rowProcessingState.getSession(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + final EntityHolder holder = persistenceContext.getEntityHolder( getEntityKey() ); + Object instance = holder.getEntity(); + assert instance != null : "The real entity instance must be resolved in the `resolveInstance()` phase"; + if ( holder.getEntityInitializer() == this ) { + return initializeEntity( instance, rowProcessingState ) + .thenAccept( vv -> { + lazyInitializer.setImplementation( instance ); + setEntityInstanceForNotify( instance ); + } ); + } + return voidFuture().thenAccept( vv -> { + lazyInitializer.setImplementation( instance ); + setEntityInstanceForNotify( instance ); + + } ); } else { // FIXME: Read from cache if possible @@ -103,35 +119,6 @@ public CompletionStage reactiveInitializeInstance(ReactiveRowProcessingSta return voidFuture(); } - private CompletionStage lazyInitialize(ReactiveRowProcessingState rowProcessingState, LazyInitializer lazyInitializer) { - final SharedSessionContractImplementor session = rowProcessingState.getSession(); - final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); - final EntityHolder holder = persistenceContext.getEntityHolder( getEntityKey() ); - Object instance = holder.getEntity(); - if ( instance == null ) { - return resolveInstance( rowProcessingState, lazyInitializer, persistenceContext ); - } - lazyInitializer.setImplementation( instance ); - setEntityInstanceForNotify( instance ); - return voidFuture(); - } - - private CompletionStage resolveInstance( - ReactiveRowProcessingState rowProcessingState, - LazyInitializer lazyInitializer, - PersistenceContext persistenceContext) { - final Object instance = super.resolveInstance( - getEntityKey().getIdentifier(), - persistenceContext.getEntityHolder( getEntityKey() ), - rowProcessingState - ); - return initializeEntity( instance, rowProcessingState ) - .thenAccept( v -> { - lazyInitializer.setImplementation( instance ); - setEntityInstanceForNotify( instance ); - } ); - } - private CompletionStage initializeEntity(Object toInitialize, RowProcessingState rowProcessingState) { if ( !skipInitialization( toInitialize, rowProcessingState ) ) { assert consistentInstance( toInitialize, rowProcessingState ); diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchByUniqueKeyInitializer.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchByUniqueKeyInitializer.java index e7e08e767..e975eecac 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchByUniqueKeyInitializer.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchByUniqueKeyInitializer.java @@ -41,28 +41,29 @@ public ReactiveEntitySelectFetchByUniqueKeyInitializer( @Override public CompletionStage reactiveInitializeInstance(ReactiveRowProcessingState rowProcessingState) { - if ( entityInstance != null || isInitialized ) { + if ( getEntityInstance() != null || isEntityInitialized() ) { return voidFuture(); } + state = State.RESOLVED; final EntityInitializer parentEntityInitializer = getParentEntityInitializer( parentAccess ); if ( parentEntityInitializer != null && parentEntityInitializer.getEntityKey() != null ) { // make sure parentEntityInitializer.resolveInstance has been called before parentEntityInitializer.resolveInstance( rowProcessingState ); if ( parentEntityInitializer.isEntityInitialized() ) { - isInitialized = true; + initializeState(); return voidFuture(); } } if ( !isAttributeAssignableToConcreteDescriptor() ) { - isInitialized = true; + initializeState(); return voidFuture(); } final Object entityIdentifier = keyAssembler.assemble( rowProcessingState ); if ( entityIdentifier == null ) { - isInitialized = true; + initializeState(); return voidFuture(); } final String entityName = concreteDescriptor.getEntityName(); @@ -104,7 +105,7 @@ public CompletionStage reactiveInitializeInstance(ReactiveRowProcessingSta if ( entityInstance != null ) { setEntityInstance( persistenceContext.proxyFor( entityInstance ) ); } - isInitialized = true; + initializeState(); return voidFuture(); } diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchInitializer.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchInitializer.java index d648d2d11..a20608c8f 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchInitializer.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/sql/results/graph/entity/internal/ReactiveEntitySelectFetchInitializer.java @@ -102,17 +102,18 @@ public CompletionStage reactiveInitializeInstance(ReactiveRowProcessingSta final EntityInitializer parentEntityInitializer = parentAccess.findFirstEntityInitializer(); if ( parentEntityInitializer != null && parentEntityInitializer.isEntityInitialized() ) { - isInitialized = true; + initializeState(); return voidFuture(); } if ( !isAttributeAssignableToConcreteDescriptor() ) { + initializeState(); return voidFuture(); } final Object entityIdentifier = keyAssembler.assemble( rowProcessingState ); if ( entityIdentifier == null ) { - isInitialized = true; + initializeState(); return voidFuture(); } @@ -145,7 +146,7 @@ public CompletionStage reactiveInitializeInstance(ReactiveRowProcessingSta entityInstance = holder.getEntity(); if ( holder.getEntityInitializer() == null ) { if ( entityInstance != null && Hibernate.isInitialized( entityInstance ) ) { - isInitialized = true; + initializeState(); return voidFuture(); } } @@ -159,11 +160,11 @@ else if ( holder.getEntityInitializer() != this ) { holder.getEntityInitializer() ); } - isInitialized = true; + initializeState(); return voidFuture(); } else if ( entityInstance == null ) { - isInitialized = true; + initializeState(); return voidFuture(); } } @@ -202,11 +203,15 @@ else if ( entityInstance == null ) { if ( lazyInitializer != null ) { lazyInitializer.setUnwrap( unwrapProxy ); } - isInitialized = true; + initializeState(); return voidFuture(); } ); } + protected void initializeState() { + state = State.INITIALIZED; + } + protected ToOneAttributeMapping toOneMapping() { return (ToOneAttributeMapping) getInitializedPart(); }