HHH-16559 Disable batch fetching for dynamic instantiation queries

This commit is contained in:
Marco Belladelli 2023-05-10 13:00:03 +02:00
parent 2cd7104d9d
commit a64490ed50
3 changed files with 19 additions and 4 deletions

View File

@ -18,11 +18,14 @@ import org.hibernate.sql.exec.spi.ExecutionContext;
* @author Steve Ebersole
*/
public interface AssemblerCreationState {
default boolean isScrollResult() {
return false;
}
default boolean isDynamicInstantiation() {
return false;
}
LockMode determineEffectiveLockMode(String identificationVariable);
Initializer resolveInitializer(

View File

@ -94,6 +94,9 @@ public class EntitySelectFetchInitializerBuilder {
.effectivelyBatchLoadable( entityPersister ) ) {
return NONE;
}
else if ( creationState.isDynamicInstantiation() ) {
return BatchMode.BATCH_INITIALIZE;
}
while ( parentAccess.isEmbeddableInitializer() ) {
final EmbeddableInitializer embeddableInitializer = parentAccess.asEmbeddableInitializer();
final EmbeddableValuedModelPart initializedPart = embeddableInitializer.getInitializedPart();

View File

@ -6,14 +6,12 @@
*/
package org.hibernate.sql.results.internal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.hibernate.CacheMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.cache.spi.access.CollectionDataAccess;
@ -28,7 +26,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.persister.collection.CollectionPersister;
@ -42,6 +39,7 @@ import org.hibernate.sql.results.ResultsLogger;
import org.hibernate.sql.results.graph.AssemblerCreationState;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.graph.Initializer;
import org.hibernate.sql.results.graph.instantiation.DynamicInstantiationResult;
import org.hibernate.sql.results.jdbc.spi.JdbcValues;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMapping;
import org.hibernate.sql.results.spi.RowReader;
@ -77,12 +75,23 @@ public class ResultsHelper {
final List<DomainResultAssembler<?>> assemblers = jdbcValuesMapping.resolveAssemblers(
new AssemblerCreationState() {
Boolean dynamicInstantiation;
@Override
public boolean isScrollResult() {
return executionContext.isScrollResult();
}
@Override
public boolean isDynamicInstantiation() {
if ( dynamicInstantiation == null ) {
dynamicInstantiation = jdbcValuesMapping.getDomainResults()
.stream()
.anyMatch( domainResult -> domainResult instanceof DynamicInstantiationResult );
}
return dynamicInstantiation;
}
@Override
public LockMode determineEffectiveLockMode(String identificationVariable) {
return lockOptions.getEffectiveLockMode( identificationVariable );