HHH-17983 Remove entity keys from batch queue before loading

This commit is contained in:
Marco Belladelli 2024-04-23 15:54:44 +02:00
parent c846bc3ec2
commit 9346c28c8e
2 changed files with 12 additions and 11 deletions

View File

@ -134,6 +134,13 @@ public class EntityBatchLoaderArrayParam<T>
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<T>
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

View File

@ -141,7 +141,6 @@ public class EntityBatchLoaderInPredicate<T>
);
final BatchFetchQueue batchFetchQueue = session.getPersistenceContextInternal().getBatchFetchQueue();
final List<EntityKey> entityKeys = arrayList( sqlBatchSize );
chunker.processChunks(
idsToInitialize,
@ -166,7 +165,11 @@ public class EntityBatchLoaderInPredicate<T>
},
(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<T>
}
},
(startIndex, nonNullElementCount) -> {
entityKeys.forEach( batchFetchQueue::removeBatchLoadableEntityKey );
entityKeys.clear();
},
session
);