From c1a7a14d1cf207fa605026be600b9fc160181afd Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 1 Mar 2021 09:53:43 +0100 Subject: [PATCH] HHH-14471 Fix concurrency issue due to builder sharing in DynamicBatchingEntityLoader --- .../entity/plan/DynamicBatchingEntityLoader.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/DynamicBatchingEntityLoader.java b/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/DynamicBatchingEntityLoader.java index 6f51a942bd..6bc11cb8cd 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/DynamicBatchingEntityLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/DynamicBatchingEntityLoader.java @@ -27,7 +27,7 @@ public class DynamicBatchingEntityLoader extends BatchingEntityLoader { private static final Logger log = Logger.getLogger( DynamicBatchingEntityLoader.class ); private final int maxBatchSize; - private final EntityLoader.Builder entityLoaderBuilder; + private final LoadQueryInfluencers loadQueryInfluencers; public DynamicBatchingEntityLoader( OuterJoinLoadable persister, @@ -37,10 +37,7 @@ public class DynamicBatchingEntityLoader extends BatchingEntityLoader { LoadQueryInfluencers loadQueryInfluencers) { super( persister ); this.maxBatchSize = maxBatchSize; - - entityLoaderBuilder = EntityLoader.forEntity( persister ) - .withInfluencers( loadQueryInfluencers ) - .withLockOptions( lockOptions ); + this.loadQueryInfluencers = loadQueryInfluencers; } @Override @@ -67,7 +64,12 @@ public class DynamicBatchingEntityLoader extends BatchingEntityLoader { log.debugf( "Batch loading entity: %s", MessageHelper.infoString( persister(), idsToLoad, session.getFactory() ) ); } - final EntityLoader dynamicLoader = entityLoaderBuilder.withBatchSize( idsToLoad.length ).byPrimaryKey(); + + final EntityLoader dynamicLoader = EntityLoader.forEntity( (OuterJoinLoadable) persister() ) + .withInfluencers( loadQueryInfluencers ) + .withLockOptions( lockOptions ) + .withBatchSize( idsToLoad.length ) + .byPrimaryKey(); final List results = dynamicLoader.loadEntityBatch( session,