diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderArrayParam.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderArrayParam.java index 0c1e561acd..a36590b4a7 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderArrayParam.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderArrayParam.java @@ -134,6 +134,13 @@ public class EntityBatchLoaderArrayParam getLoadable().getEntityName(), id, Arrays.toString(idsToInitialize) ); } + for ( Object initializedId : idsToInitialize ) { + if ( initializedId != null ) { + // found or not, remove the key from the batch-fetch queue + removeBatchLoadableEntityKey( initializedId, getLoadable(), session ); + } + } + LoaderHelper.loadByArrayParameter( idsToInitialize, sqlAst, @@ -147,13 +154,6 @@ public class EntityBatchLoaderArrayParam readOnly, session ); - - for ( Object initializedId : idsToInitialize ) { - if ( initializedId != null ) { - // found or not, remove the key from the batch-fetch queue - removeBatchLoadableEntityKey( initializedId, getLoadable(), session ); - } - } } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java index 6f2ea798cb..04d27c5f54 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java @@ -141,7 +141,6 @@ public class EntityBatchLoaderInPredicate ); final BatchFetchQueue batchFetchQueue = session.getPersistenceContextInternal().getBatchFetchQueue(); - final List entityKeys = arrayList( sqlBatchSize ); chunker.processChunks( idsToInitialize, @@ -166,7 +165,11 @@ public class EntityBatchLoaderInPredicate }, (key, relativePosition, absolutePosition) -> { if ( key != null ) { - entityKeys.add( session.generateEntityKey( key, getLoadable().getEntityPersister() ) ); + final EntityKey entityKey = session.generateEntityKey( + key, + getLoadable().getEntityPersister() + ); + batchFetchQueue.removeBatchLoadableEntityKey( entityKey ); } }, (startIndex) -> { @@ -181,8 +184,6 @@ public class EntityBatchLoaderInPredicate } }, (startIndex, nonNullElementCount) -> { - entityKeys.forEach( batchFetchQueue::removeBatchLoadableEntityKey ); - entityKeys.clear(); }, session );