Fix too eager collection fetching, wrong fetch timing determination and `entityAlias = :param` usages

This commit is contained in:
Christian Beikov 2021-09-10 10:10:14 +02:00
parent 6096bbdfa1
commit e59f2b9761
4 changed files with 9 additions and 8 deletions

View File

@ -529,7 +529,7 @@ public class PluralAttributeMappingImpl
}
}
if ( getCollectionDescriptor().getCollectionType().hasHolder() || !getCollectionDescriptor().isLazy() ) {
if ( getCollectionDescriptor().getCollectionType().hasHolder() ) {
return createSelectEagerCollectionFetch( fetchParent, fetchablePath, creationState, sqlAstCreationState );
}

View File

@ -124,11 +124,8 @@ public final class FetchOptionsHelper {
return FetchTiming.IMMEDIATE;
}
case BATCH:
case SUBSELECT: {
return FetchTiming.DELAYED;
}
case SUBSELECT:
default: {
// SELECT case, can be either
return isSubsequentSelectDelayed( type, sessionFactory )
? FetchTiming.DELAYED
: FetchTiming.IMMEDIATE;

View File

@ -160,6 +160,10 @@ public class SqmMappingModelHelper {
return pluralPart.findSubPart( sqmPath.getReferencedPathSource().getPathName(), null );
}
if ( sqmPath.getLhs() == null ) {
final EntityDomainType<?> entityDomainType = (EntityDomainType<?>) sqmPath.getReferencedPathSource();
return domainModel.findEntityDescriptor( entityDomainType.getHibernateEntityName() );
}
final TableGroup lhsTableGroup = tableGroupLocator.apply( sqmPath.getLhs().getNavigablePath() );
return lhsTableGroup.getModelPart().findSubPart( sqmPath.getReferencedPathSource().getPathName(), null );
}

View File

@ -11,6 +11,7 @@ import java.util.function.Function;
import org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.metamodel.model.domain.AllowableParameterType;
import org.hibernate.query.SemanticException;
@ -26,7 +27,6 @@ import org.hibernate.sql.ast.tree.expression.SqlTupleContainer;
import org.hibernate.sql.results.graph.basic.BasicResult;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.entity.EntityValuedFetchable;
/**
* @author Steve Ebersole
@ -49,8 +49,8 @@ public class SqmParameterInterpretation implements Expression, DomainResultProdu
this.queryParameter = queryParameter;
this.queryParameterBindingResolver = queryParameterBindingResolver;
if ( valueMapping instanceof EntityValuedFetchable ) {
this.valueMapping = ( (EntityValuedFetchable) valueMapping ).getEntityMappingType().getIdentifierMapping();
if ( valueMapping instanceof EntityValuedModelPart ) {
this.valueMapping = ( (EntityValuedModelPart) valueMapping ).getEntityMappingType().getIdentifierMapping();
}
else {
this.valueMapping = valueMapping;