From 86d1f278bc9fac203e90674e9c19de06884e32e6 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 7 Sep 2023 12:24:34 +0200 Subject: [PATCH] HHH-17173 Getting one-to-one association through a referenece to a bytecode enchanced entity fails --- .../AbstractBatchEntitySelectFetchInitializer.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java index 98793e0e78..fb26e57fa1 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/AbstractBatchEntitySelectFetchInitializer.java @@ -98,7 +98,6 @@ public abstract class AbstractBatchEntitySelectFetchInitializer extends Abstract else { entityKey = new EntityKey( entityIdentifier, concreteDescriptor ); state = State.KEY_RESOLVED; - registerResolutionListener(); } } @@ -117,6 +116,17 @@ public abstract class AbstractBatchEntitySelectFetchInitializer extends Abstract else if ( isInitialized( instance ) ) { return instance; } + else { + // the instance is not initialized but there is another initialzier that is loading it + final LoadingEntityEntry loadingEntityEntry = persistenceContext + .getLoadContexts().findLoadingEntityEntry( entityKey ); + if ( loadingEntityEntry != null ) { + return loadingEntityEntry.getEntityInstance(); + } + } + // we need to register a resolution listener only if there is not an already initialized instance + // or an instance that another initialzier is loading + registerResolutionListener(); return null; }