HHH-16743 StackOverflowError when loading a ManyToOne whith @Proxy(lazy=false)

This commit is contained in:
Andrea Boriero 2023-06-13 10:00:37 +02:00 committed by Andrea Boriero
parent 4933303f0b
commit 46bfc59cd1
1 changed files with 17 additions and 2 deletions

View File

@ -105,8 +105,11 @@ public class EntitySelectFetchInitializerBuilder {
return NONE; return NONE;
} }
else if ( creationState.isDynamicInstantiation() ) { else if ( creationState.isDynamicInstantiation() ) {
if ( canBatchInitializeBeUsed( entityPersister ) ) {
return BatchMode.BATCH_INITIALIZE; return BatchMode.BATCH_INITIALIZE;
} }
return NONE;
}
while ( parentAccess.isEmbeddableInitializer() ) { while ( parentAccess.isEmbeddableInitializer() ) {
final EmbeddableInitializer embeddableInitializer = parentAccess.asEmbeddableInitializer(); final EmbeddableInitializer embeddableInitializer = parentAccess.asEmbeddableInitializer();
final EmbeddableValuedModelPart initializedPart = embeddableInitializer.getInitializedPart(); final EmbeddableValuedModelPart initializedPart = embeddableInitializer.getInitializedPart();
@ -134,12 +137,24 @@ public class EntitySelectFetchInitializerBuilder {
if ( cacheAccess != null ) { if ( cacheAccess != null ) {
// Do batch initialization instead of batch loading if the parent entity is cacheable // Do batch initialization instead of batch loading if the parent entity is cacheable
// to avoid putting entity state into the cache at a point when the association is not yet set // to avoid putting entity state into the cache at a point when the association is not yet set
if ( canBatchInitializeBeUsed( entityPersister ) ) {
return BATCH_INITIALIZE; return BATCH_INITIALIZE;
} }
return NONE;
}
} }
return BATCH_LOAD; return BATCH_LOAD;
} }
private static boolean canBatchInitializeBeUsed(EntityPersister entityPersister) {
if ( entityPersister.getRepresentationStrategy().getProxyFactory() == null
&& entityPersister.hasSubclasses() ) {
// We cannot neither create a proxy nor instantiate the entity because we don't know the concrete type
return false;
}
return true;
}
enum BatchMode { enum BatchMode {
NONE, NONE,
BATCH_LOAD, BATCH_LOAD,