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 f3c21bbab2
commit 6b8beaaf3a
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 public abstract class AbstractBatchEntitySelectFetchInitializer extends AbstractFetchParentAccess
implements EntityInitializer { implements EntityInitializer {
protected FetchParentAccess parentAccess; protected final FetchParentAccess parentAccess;
private final NavigablePath navigablePath; private final NavigablePath navigablePath;
protected final EntityPersister concreteDescriptor; protected final EntityPersister concreteDescriptor;
@ -47,6 +47,7 @@ public abstract class AbstractBatchEntitySelectFetchInitializer extends Abstract
this.concreteDescriptor = concreteDescriptor; this.concreteDescriptor = concreteDescriptor;
this.identifierAssembler = identifierAssembler; this.identifierAssembler = identifierAssembler;
this.firstEntityInitializer = parentAccess.findFirstEntityInitializer(); this.firstEntityInitializer = parentAccess.findFirstEntityInitializer();
assert firstEntityInitializer != null : "This initializer requires parentAccess.findFirstEntityInitializer() to not be null";
} }
public ModelPart getInitializedPart() { public ModelPart getInitializedPart() {

View File

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

View File

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

View File

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

View File

@ -42,6 +42,16 @@ public class EntitySelectFetchInitializerBuilder {
keyResult.createResultAssembler( parentAccess, creationState ) 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 ); final BatchMode batchMode = determineBatchMode( entityPersister, parentAccess, creationState );
switch ( batchMode ) { switch ( batchMode ) {
case NONE: case NONE: