HHH-16740 Fetching an element collection on an entity with a composite id fails when batch size > 1

This commit is contained in:
Andrea Boriero 2023-06-05 13:34:36 +02:00 committed by Andrea Boriero
parent c44086778a
commit 3e8cfeb659
5 changed files with 12 additions and 4 deletions

View File

@ -24,7 +24,7 @@ import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
public abstract class AbstractBatchEntitySelectFetchInitializer extends AbstractFetchParentAccess
implements EntityInitializer {
protected FetchParentAccess parentAccess;
protected final FetchParentAccess parentAccess;
private final NavigablePath navigablePath;
protected final EntityPersister concreteDescriptor;
@ -47,6 +47,7 @@ public abstract class AbstractBatchEntitySelectFetchInitializer extends Abstract
this.concreteDescriptor = concreteDescriptor;
this.identifierAssembler = identifierAssembler;
this.firstEntityInitializer = parentAccess.findFirstEntityInitializer();
assert firstEntityInitializer != null : "This initializer requires parentAccess.findFirstEntityInitializer() to not be null";
}
public ModelPart getInitializedPart() {

View File

@ -133,7 +133,6 @@ public class BatchEntityInsideEmbeddableSelectFetchInitializer extends AbstractB
);
toBatchLoad.clear();
}
parentAccess = null;
}
protected static void setInstance(

View File

@ -92,7 +92,6 @@ public class BatchEntitySelectFetchInitializer extends AbstractBatchEntitySelect
);
toBatchLoad.clear();
}
parentAccess = null;
}
protected static void setInstance(

View File

@ -100,7 +100,6 @@ public class BatchInitializeEntitySelectFetchInitializer extends AbstractBatchEn
loadInstance( key, referencedModelPart, session );
}
toBatchLoad.clear();
parentAccess = null;
}
@Override

View File

@ -38,6 +38,16 @@ public class EntitySelectFetchInitializerBuilder {
keyResult.createResultAssembler( parentAccess, creationState )
);
}
if ( parentAccess.findFirstEntityInitializer() == null ) {
// Batch initializers require parentAccess.findFirstEntityInitializer() != null
return new EntitySelectFetchInitializer(
parentAccess,
fetchedAttribute,
navigablePath,
entityPersister,
keyResult.createResultAssembler( parentAccess, creationState )
);
}
final BatchMode batchMode = determineBatchMode( entityPersister, parentAccess, creationState );
switch ( batchMode ) {
case NONE: