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 d1ec1c9306
commit 47a36f630b
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
3 changed files with 19 additions and 4 deletions

View File

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

View File

@ -86,6 +86,9 @@ public class EntitySelectFetchInitializerBuilder {
if ( !entityPersister.isBatchLoadable() || creationState.isScrollResult() ) {
return BatchMode.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 );