Search in sources :

Example 6 with ModelPart

use of org.hibernate.metamodel.mapping.ModelPart in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method consumeAttributeJoin.

private TableGroup consumeAttributeJoin(SqmAttributeJoin<?, ?> sqmJoin, TableGroup lhsTableGroup, TableGroup ownerTableGroup, boolean transitive) {
    final SqmPathSource<?> pathSource = sqmJoin.getReferencedPathSource();
    final SqmJoinType sqmJoinType = sqmJoin.getSqmJoinType();
    final TableGroupJoin joinedTableGroupJoin;
    final TableGroup joinedTableGroup;
    final NavigablePath sqmJoinNavigablePath = sqmJoin.getNavigablePath();
    final ModelPart modelPart = ownerTableGroup.getModelPart().findSubPart(pathSource.getPathName(), SqmMappingModelHelper.resolveExplicitTreatTarget(sqmJoin, this));
    if (pathSource instanceof PluralPersistentAttribute) {
        assert modelPart instanceof PluralAttributeMapping;
        final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) modelPart;
        if (sqmJoin.isFetched()) {
            containsCollectionFetches = true;
        }
        joinedTableGroupJoin = pluralAttributeMapping.createTableGroupJoin(sqmJoinNavigablePath, ownerTableGroup, sqmJoin.getExplicitAlias(), sqmJoinType.getCorrespondingSqlJoinType(), sqmJoin.isFetched(), sqmJoin.getJoinPredicate() != null, this);
        joinedTableGroup = joinedTableGroupJoin.getJoinedGroup();
        pluralAttributeMapping.applyBaseRestrictions((predicate) -> {
            final PredicateCollector existing = collectionFilterPredicates.get(joinedTableGroup.getNavigablePath());
            final PredicateCollector collector;
            if (existing == null) {
                collector = new PredicateCollector(predicate);
                collectionFilterPredicates.put(joinedTableGroup.getNavigablePath(), collector);
            } else {
                collector = existing;
                collector.applyPredicate(predicate);
            }
        }, joinedTableGroup, true, getLoadQueryInfluencers().getEnabledFilters(), null, this);
    } else {
        assert modelPart instanceof TableGroupJoinProducer;
        joinedTableGroupJoin = ((TableGroupJoinProducer) modelPart).createTableGroupJoin(sqmJoinNavigablePath, ownerTableGroup, sqmJoin.getExplicitAlias(), sqmJoinType.getCorrespondingSqlJoinType(), sqmJoin.isFetched(), sqmJoin.getJoinPredicate() != null, this);
        joinedTableGroup = joinedTableGroupJoin.getJoinedGroup();
        // Left or inner singular attribute joins without a predicate can be safely optimized away
        if (sqmJoin.getJoinPredicate() != null || sqmJoinType != SqmJoinType.INNER && sqmJoinType != SqmJoinType.LEFT) {
            joinedTableGroup.getPrimaryTableReference();
        }
    }
    lhsTableGroup.addTableGroupJoin(joinedTableGroupJoin);
    getFromClauseIndex().register(sqmJoin, joinedTableGroup);
    registerPluralTableGroupParts(joinedTableGroup);
    // For joins we also need to register the table groups for the treats
    if (joinedTableGroup instanceof PluralTableGroup) {
        final PluralTableGroup pluralTableGroup = (PluralTableGroup) joinedTableGroup;
        for (SqmFrom<?, ?> sqmTreat : sqmJoin.getSqmTreats()) {
            if (pluralTableGroup.getElementTableGroup() != null) {
                getFromClauseAccess().registerTableGroup(sqmTreat.getNavigablePath().append(CollectionPart.Nature.ELEMENT.getName()), pluralTableGroup.getElementTableGroup());
            }
            if (pluralTableGroup.getIndexTableGroup() != null) {
                getFromClauseAccess().registerTableGroup(sqmTreat.getNavigablePath().append(CollectionPart.Nature.INDEX.getName()), pluralTableGroup.getIndexTableGroup());
            }
        }
    } else {
        for (SqmFrom<?, ?> sqmTreat : sqmJoin.getSqmTreats()) {
            getFromClauseAccess().registerTableGroup(sqmTreat.getNavigablePath(), joinedTableGroup);
        }
    }
    // add any additional join restrictions
    if (sqmJoin.getJoinPredicate() != null) {
        if (sqmJoin.isFetched()) {
            QueryLogging.QUERY_MESSAGE_LOGGER.debugf("Join fetch [" + sqmJoinNavigablePath + "] is restricted");
        }
        final SqmJoin<?, ?> oldJoin = currentlyProcessingJoin;
        currentlyProcessingJoin = sqmJoin;
        joinedTableGroupJoin.applyPredicate(visitNestedTopLevelPredicate(sqmJoin.getJoinPredicate()));
        currentlyProcessingJoin = oldJoin;
    }
    if (transitive) {
        consumeExplicitJoins(sqmJoin, joinedTableGroup);
    }
    return joinedTableGroup;
}
Also used : VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) SyntheticVirtualTableGroup(org.hibernate.sql.ast.tree.from.SyntheticVirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) NavigablePath(org.hibernate.spi.NavigablePath) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) PluralPersistentAttribute(org.hibernate.metamodel.model.domain.PluralPersistentAttribute) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) SqmJoinType(org.hibernate.query.sqm.tree.SqmJoinType) PredicateCollector(org.hibernate.sql.ast.tree.predicate.PredicateCollector)

Example 7 with ModelPart

use of org.hibernate.metamodel.mapping.ModelPart in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method determineValueMapping.

protected MappingModelExpressible<?> determineValueMapping(SqmParameter<?> sqmParameter) {
    log.debugf("Determining mapping-model type for SqmParameter : %s", sqmParameter);
    final QueryParameterImplementor<?> queryParameter = domainParameterXref.getQueryParameter(sqmParameter);
    final QueryParameterBinding<?> binding = domainParameterBindings.getBinding(queryParameter);
    BindableType<?> paramType = binding.getBindType();
    if (paramType == null) {
        paramType = queryParameter.getHibernateType();
        if (paramType == null) {
            paramType = sqmParameter.getAnticipatedType();
        }
    }
    if (paramType == null) {
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
        // Default to the Object type
        return basicType(Object.class);
    } else if (paramType instanceof MappingModelExpressible<?>) {
        final MappingModelExpressible<?> paramModelType = (MappingModelExpressible<?>) paramType;
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        // Prefer the model part type instead of the bind type if possible as the model part type contains size information
        if (inferredValueMapping instanceof ModelPart) {
            final JdbcMapping paramJdbcMapping = paramModelType.getJdbcMappings().get(0);
            final JdbcMapping inferredJdbcMapping = inferredValueMapping.getJdbcMappings().get(0);
            // If the bind type has a different JDBC type, we prefer that
            if (paramJdbcMapping.getJdbcType() == inferredJdbcMapping.getJdbcType()) {
                return inferredValueMapping;
            }
        }
        return paramModelType;
    } else if (sqmParameter.getAnticipatedType() == null) {
        // this should indicate the condition that the user query did not define an
        // explicit type in regard to this parameter.  Here we should prefer the
        // inferrable type and fallback to resolving the binding type
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
    } else if (paramType instanceof EntityDomainType) {
        // In JPA Criteria, it is possible to define a parameter of an entity type,
        // but that should infer the mapping type from context,
        // otherwise this would default to binding the PK which might be wrong
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
    }
    final SqmExpressible<?> paramSqmType = paramType.resolveExpressible(creationContext.getSessionFactory());
    if (paramSqmType instanceof SqmPath) {
        final SqmPath<?> sqmPath = (SqmPath<?>) paramSqmType;
        final NavigablePath navigablePath = sqmPath.getNavigablePath();
        if (navigablePath.getParent() != null) {
            final TableGroup tableGroup = getFromClauseAccess().getTableGroup(navigablePath.getParent());
            return tableGroup.getModelPart().findSubPart(navigablePath.getLocalName(), null);
        }
        return getFromClauseAccess().getTableGroup(navigablePath).getModelPart();
    }
    if (paramSqmType instanceof BasicValuedMapping) {
        return (BasicValuedMapping) paramSqmType;
    }
    if (paramSqmType instanceof CompositeSqmPathSource || paramSqmType instanceof EmbeddableDomainType<?>) {
        // Try to infer the value mapping since the other side apparently is a path source
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
        throw new NotYetImplementedFor6Exception("Support for embedded-valued parameters not yet implemented");
    }
    if (paramSqmType instanceof SqmPathSource<?> || paramSqmType instanceof BasicDomainType<?>) {
        // Try to infer the value mapping since the other side apparently is a path source
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
        final BasicType basicTypeForJavaType = getTypeConfiguration().getBasicTypeForJavaType(paramSqmType.getExpressibleJavaType().getJavaTypeClass());
        if (basicTypeForJavaType == null) {
            if (paramSqmType instanceof EntityDomainType) {
                return getIdType((EntityDomainType) paramSqmType);
            } else if (paramSqmType instanceof SingularAttribute) {
                final Type type = ((SingularAttribute) paramSqmType).getType();
                if (type instanceof EntityDomainType) {
                    return getIdType((EntityDomainType) type);
                }
            }
        }
        return basicTypeForJavaType;
    }
    throw new ConversionException("Could not determine ValueMapping for SqmParameter: " + sqmParameter);
}
Also used : NavigablePath(org.hibernate.spi.NavigablePath) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) SyntheticVirtualTableGroup(org.hibernate.sql.ast.tree.from.SyntheticVirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) BasicType(org.hibernate.type.BasicType) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) SelfInterpretingSqmPath(org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath) SqmPath(org.hibernate.query.sqm.tree.domain.SqmPath) DiscriminatorSqmPath(org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath) CompositeSqmPathSource(org.hibernate.metamodel.model.domain.internal.CompositeSqmPathSource) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) BasicType(org.hibernate.type.BasicType) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) TemporalJavaType(org.hibernate.type.descriptor.java.TemporalJavaType) JdbcType(org.hibernate.type.descriptor.jdbc.JdbcType) BasicDomainType(org.hibernate.metamodel.model.domain.BasicDomainType) UserVersionType(org.hibernate.usertype.UserVersionType) BindableType(org.hibernate.query.BindableType) SqmJoinType(org.hibernate.query.sqm.tree.SqmJoinType) NullType(org.hibernate.type.NullType) EmbeddableDomainType(org.hibernate.metamodel.model.domain.EmbeddableDomainType) TemporalType(jakarta.persistence.TemporalType) JavaObjectType(org.hibernate.type.JavaObjectType) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) AbstractTimeZoneStorageCompositeUserType(org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType) FetchClauseType(org.hibernate.query.sqm.FetchClauseType) Type(jakarta.persistence.metamodel.Type) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) SqmParameterizedEntityType(org.hibernate.query.sqm.tree.expression.SqmParameterizedEntityType) SqmLiteralEntityType(org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType) JavaType(org.hibernate.type.descriptor.java.JavaType) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) ReturnableType(org.hibernate.query.ReturnableType) EnumJavaType(org.hibernate.type.descriptor.java.EnumJavaType) SimpleDomainType(org.hibernate.metamodel.model.domain.SimpleDomainType) EmbeddableMappingType(org.hibernate.metamodel.mapping.EmbeddableMappingType) CastType(org.hibernate.query.sqm.CastType) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType)

Example 8 with ModelPart

use of org.hibernate.metamodel.mapping.ModelPart in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method visitTableGroup.

private Expression visitTableGroup(TableGroup tableGroup, SqmFrom<?, ?> path) {
    final ModelPartContainer modelPart;
    final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
    // For plain SqmFrom node uses, prefer the mapping type from the context if possible
    if (!(inferredValueMapping instanceof ModelPartContainer)) {
        modelPart = tableGroup.getModelPart();
    } else {
        modelPart = (ModelPartContainer) inferredValueMapping;
    }
    final ModelPart resultModelPart;
    final ModelPart interpretationModelPart;
    final TableGroup parentGroupToUse;
    if (modelPart instanceof ToOneAttributeMapping) {
        final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) modelPart;
        final ModelPart targetPart = toOneAttributeMapping.getForeignKeyDescriptor().getPart(toOneAttributeMapping.getSideNature().inverse());
        if (tableGroup.getModelPart().getPartMappingType() == modelPart.getPartMappingType()) {
            resultModelPart = targetPart;
        } else {
            // If the table group is for a different mapping type i.e. an inheritance subtype,
            // lookup the target part on that mapping type
            resultModelPart = tableGroup.getModelPart().findSubPart(targetPart.getPartName(), null);
        }
        interpretationModelPart = modelPart;
        parentGroupToUse = null;
    } else if (modelPart instanceof PluralAttributeMapping) {
        final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) modelPart;
        final CollectionPart elementDescriptor = pluralAttributeMapping.getElementDescriptor();
        if (elementDescriptor instanceof EntityCollectionPart) {
            // Usually, we need to resolve to the PK for visitTableGroup
            final EntityCollectionPart collectionPart = (EntityCollectionPart) elementDescriptor;
            final ModelPart collectionTargetPart = collectionPart.getForeignKeyDescriptor().getPart(collectionPart.getSideNature().inverse());
            final EntityIdentifierMapping identifierMapping = collectionPart.getEntityMappingType().getIdentifierMapping();
            // If the FK points to the PK, we can use the FK part though, if this is not a root
            if (collectionTargetPart == identifierMapping && !(path instanceof SqmRoot<?>)) {
                resultModelPart = collectionPart.getForeignKeyDescriptor().getPart(collectionPart.getSideNature());
            } else {
                resultModelPart = identifierMapping;
            }
        } else {
            resultModelPart = elementDescriptor;
        }
        interpretationModelPart = elementDescriptor;
        parentGroupToUse = null;
    } else if (modelPart instanceof EntityCollectionPart) {
        // Usually, we need to resolve to the PK for visitTableGroup
        final EntityCollectionPart collectionPart = (EntityCollectionPart) modelPart;
        final ModelPart collectionTargetPart = collectionPart.getForeignKeyDescriptor().getPart(collectionPart.getSideNature().inverse());
        final EntityIdentifierMapping identifierMapping = collectionPart.getEntityMappingType().getIdentifierMapping();
        // If the FK points to the PK, we can use the FK part though, if this is not a root
        if (collectionTargetPart == identifierMapping && !(path instanceof SqmRoot<?>)) {
            resultModelPart = collectionPart.getForeignKeyDescriptor().getPart(collectionPart.getSideNature());
        } else {
            resultModelPart = identifierMapping;
        }
        interpretationModelPart = modelPart;
        parentGroupToUse = findTableGroup(tableGroup.getNavigablePath().getParent());
    } else if (modelPart instanceof EntityMappingType) {
        resultModelPart = ((EntityMappingType) modelPart).getIdentifierMapping();
        interpretationModelPart = modelPart;
        // todo: I think this will always be null anyways because EntityMappingType will only be the model part
        // of a TableGroup if that is a root TableGroup, so check if we can just switch to null
        parentGroupToUse = findTableGroup(tableGroup.getNavigablePath().getParent());
    } else {
        resultModelPart = modelPart;
        interpretationModelPart = modelPart;
        parentGroupToUse = null;
    }
    final NavigablePath navigablePath;
    if (interpretationModelPart == modelPart) {
        navigablePath = tableGroup.getNavigablePath();
    } else {
        navigablePath = tableGroup.getNavigablePath().append(interpretationModelPart.getPartName());
    }
    final Expression result;
    if (interpretationModelPart instanceof EntityValuedModelPart) {
        final boolean expandToAllColumns;
        if (currentClauseStack.getCurrent() == Clause.GROUP) {
            // When the table group is known to be fetched i.e. a fetch join
            // but also when the from clause is part of the select clause
            // we need to expand to all columns, as we also expand this to all columns in the select clause
            expandToAllColumns = tableGroup.isFetched() || selectClauseContains(path);
        } else {
            expandToAllColumns = false;
        }
        final EntityValuedModelPart mapping = (EntityValuedModelPart) interpretationModelPart;
        EntityMappingType mappingType;
        if (path instanceof SqmTreatedPath) {
            mappingType = creationContext.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor(((SqmTreatedPath<?, ?>) path).getTreatTarget().getHibernateEntityName());
        } else {
            mappingType = mapping.getEntityMappingType();
        }
        result = EntityValuedPathInterpretation.from(navigablePath, parentGroupToUse == null ? tableGroup : parentGroupToUse, expandToAllColumns ? null : resultModelPart, (EntityValuedModelPart) interpretationModelPart, mappingType, this);
    } else if (interpretationModelPart instanceof EmbeddableValuedModelPart) {
        final EmbeddableValuedModelPart mapping = (EmbeddableValuedModelPart) resultModelPart;
        result = new EmbeddableValuedPathInterpretation<>(mapping.toSqlExpression(tableGroup, currentClauseStack.getCurrent(), this, getSqlAstCreationState()), navigablePath, (EmbeddableValuedModelPart) interpretationModelPart, tableGroup);
    } else {
        assert interpretationModelPart instanceof BasicValuedModelPart;
        final BasicValuedModelPart mapping = (BasicValuedModelPart) resultModelPart;
        final TableReference tableReference = tableGroup.resolveTableReference(navigablePath.append(resultModelPart.getPartName()), mapping.getContainingTableExpression());
        final Expression expression = getSqlExpressionResolver().resolveSqlExpression(createColumnReferenceKey(tableReference, mapping.getSelectionExpression()), sacs -> new ColumnReference(tableReference.getIdentificationVariable(), mapping, getCreationContext().getSessionFactory()));
        final ColumnReference columnReference;
        if (expression instanceof ColumnReference) {
            columnReference = (ColumnReference) expression;
        } else if (expression instanceof SqlSelectionExpression) {
            final Expression selectedExpression = ((SqlSelectionExpression) expression).getSelection().getExpression();
            assert selectedExpression instanceof ColumnReference;
            columnReference = (ColumnReference) selectedExpression;
        } else {
            throw new UnsupportedOperationException("Unsupported basic-valued path expression : " + expression);
        }
        result = new BasicValuedPathInterpretation<>(columnReference, navigablePath, (BasicValuedModelPart) interpretationModelPart, tableGroup);
    }
    return withTreatRestriction(result, path);
}
Also used : VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) SqmToDuration(org.hibernate.query.sqm.tree.expression.SqmToDuration) Statement(org.hibernate.sql.ast.tree.Statement) SqmFieldLiteral(org.hibernate.query.sqm.tree.expression.SqmFieldLiteral) BasicType(org.hibernate.type.BasicType) MultipleBagFetchException(org.hibernate.loader.MultipleBagFetchException) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) JdbcMappingContainer(org.hibernate.metamodel.mapping.JdbcMappingContainer) SelfInterpretingSqmPath(org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath) TemporalJavaType(org.hibernate.type.descriptor.java.TemporalJavaType) EntityVersionMapping(org.hibernate.metamodel.mapping.EntityVersionMapping) PluralValuedSimplePathInterpretation(org.hibernate.query.sqm.sql.internal.PluralValuedSimplePathInterpretation) InSubQueryPredicate(org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate) JdbcType(org.hibernate.type.descriptor.jdbc.JdbcType) SqmSummarization(org.hibernate.query.sqm.tree.expression.SqmSummarization) Optimizer(org.hibernate.id.enhanced.Optimizer) AbstractSqlAstTranslator(org.hibernate.sql.ast.spi.AbstractSqlAstTranslator) SqmBooleanExpressionPredicate(org.hibernate.query.sqm.tree.predicate.SqmBooleanExpressionPredicate) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) StandardStack(org.hibernate.internal.util.collections.StandardStack) SqmCteContainer(org.hibernate.query.sqm.tree.cte.SqmCteContainer) SqmJoin(org.hibernate.query.sqm.tree.from.SqmJoin) SECOND(org.hibernate.query.sqm.TemporalUnit.SECOND) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) SqmPath(org.hibernate.query.sqm.tree.domain.SqmPath) FetchParent(org.hibernate.sql.results.graph.FetchParent) FilterHelper(org.hibernate.internal.FilterHelper) SearchClauseSpecification(org.hibernate.sql.ast.tree.cte.SearchClauseSpecification) JdbcTypeIndicators(org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators) SelfRenderingPredicate(org.hibernate.sql.ast.tree.predicate.SelfRenderingPredicate) SqmBasicValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath) Supplier(java.util.function.Supplier) JdbcParameterBindings(org.hibernate.sql.exec.spi.JdbcParameterBindings) LinkedHashMap(java.util.LinkedHashMap) CteTable(org.hibernate.sql.ast.tree.cte.CteTable) BasicSqmPathSource(org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource) SqmTuple(org.hibernate.query.sqm.tree.expression.SqmTuple) BasicDomainType(org.hibernate.metamodel.model.domain.BasicDomainType) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmDynamicInstantiationTarget(org.hibernate.query.sqm.tree.select.SqmDynamicInstantiationTarget) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) NegatedPredicate(org.hibernate.sql.ast.tree.predicate.NegatedPredicate) TimestampaddFunction(org.hibernate.dialect.function.TimestampaddFunction) SqmVisitableNode(org.hibernate.query.sqm.tree.SqmVisitableNode) DeleteStatement(org.hibernate.sql.ast.tree.delete.DeleteStatement) QueryParameterBindings(org.hibernate.query.spi.QueryParameterBindings) LikePredicate(org.hibernate.sql.ast.tree.predicate.LikePredicate) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping) QueryLiteral(org.hibernate.sql.ast.tree.expression.QueryLiteral) Fetch(org.hibernate.sql.results.graph.Fetch) SUBTRACT(org.hibernate.query.sqm.BinaryArithmeticOperator.SUBTRACT) SqlSelectionImpl(org.hibernate.sql.results.internal.SqlSelectionImpl) SqmFromClause(org.hibernate.query.sqm.tree.from.SqmFromClause) SqmRoot(org.hibernate.query.sqm.tree.from.SqmRoot) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) UserVersionType(org.hibernate.usertype.UserVersionType) Bindable(org.hibernate.metamodel.mapping.Bindable) PredicateCollector(org.hibernate.sql.ast.tree.predicate.PredicateCollector) ADD(org.hibernate.query.sqm.BinaryArithmeticOperator.ADD) TimestampdiffFunction(org.hibernate.dialect.function.TimestampdiffFunction) SqmFkExpression(org.hibernate.query.sqm.tree.domain.SqmFkExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) SqmIndexedCollectionAccessPath(org.hibernate.query.sqm.tree.domain.SqmIndexedCollectionAccessPath) SqmLiteralNull(org.hibernate.query.sqm.tree.expression.SqmLiteralNull) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) BetweenPredicate(org.hibernate.sql.ast.tree.predicate.BetweenPredicate) AbstractJdbcParameter(org.hibernate.sql.exec.internal.AbstractJdbcParameter) JdbcParameterImpl(org.hibernate.sql.exec.internal.JdbcParameterImpl) SqmInsertSelectStatement(org.hibernate.query.sqm.tree.insert.SqmInsertSelectStatement) Assignable(org.hibernate.sql.ast.tree.update.Assignable) Any(org.hibernate.sql.ast.tree.expression.Any) Assignment(org.hibernate.sql.ast.tree.update.Assignment) SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) OrderByFragment(org.hibernate.metamodel.mapping.ordering.OrderByFragment) SqmJpaCriteriaParameterWrapper(org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper) SqmNegatedPredicate(org.hibernate.query.sqm.tree.predicate.SqmNegatedPredicate) QueryTransformer(org.hibernate.sql.ast.tree.expression.QueryTransformer) SqlAstProcessingState(org.hibernate.sql.ast.spi.SqlAstProcessingState) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) ExistsPredicate(org.hibernate.sql.ast.tree.predicate.ExistsPredicate) SqmAliasedNode(org.hibernate.query.sqm.tree.select.SqmAliasedNode) NATIVE(org.hibernate.query.sqm.TemporalUnit.NATIVE) OptimizableGenerator(org.hibernate.id.OptimizableGenerator) Function(java.util.function.Function) SqmEnumLiteral(org.hibernate.query.sqm.tree.expression.SqmEnumLiteral) ExtractUnit(org.hibernate.sql.ast.tree.expression.ExtractUnit) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ModelPart(org.hibernate.metamodel.mapping.ModelPart) SqmTreatedRoot(org.hibernate.query.sqm.tree.domain.SqmTreatedRoot) SqmEvery(org.hibernate.query.sqm.tree.expression.SqmEvery) SqlTreeCreationException(org.hibernate.sql.ast.SqlTreeCreationException) SqlAliasBaseManager(org.hibernate.sql.ast.spi.SqlAliasBaseManager) SqlAstQueryPartProcessingStateImpl(org.hibernate.query.sqm.sql.internal.SqlAstQueryPartProcessingStateImpl) CompositeNestedGeneratedValueGenerator(org.hibernate.id.CompositeNestedGeneratedValueGenerator) SqmUnaryOperation(org.hibernate.query.sqm.tree.expression.SqmUnaryOperation) UnaryArithmeticOperator(org.hibernate.query.sqm.UnaryArithmeticOperator) Consumer(java.util.function.Consumer) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) SqlTypedMappingJdbcParameter(org.hibernate.sql.exec.internal.SqlTypedMappingJdbcParameter) NonAggregatedCompositeSimplePath(org.hibernate.query.sqm.tree.domain.NonAggregatedCompositeSimplePath) BasicValueConverter(org.hibernate.metamodel.model.convert.spi.BasicValueConverter) Arrays(java.util.Arrays) SqmExpressible(org.hibernate.query.sqm.SqmExpressible) SqmFormat(org.hibernate.query.sqm.tree.expression.SqmFormat) EPOCH(org.hibernate.query.sqm.TemporalUnit.EPOCH) SqmCaseSimple(org.hibernate.query.sqm.tree.expression.SqmCaseSimple) SqlAstTreeHelper(org.hibernate.sql.ast.spi.SqlAstTreeHelper) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) SqmTreatedPath(org.hibernate.query.sqm.tree.domain.SqmTreatedPath) BigDecimal(java.math.BigDecimal) SqmAliasedNodeRef(org.hibernate.query.sqm.tree.expression.SqmAliasedNodeRef) BindableType(org.hibernate.query.BindableType) SqmCastTarget(org.hibernate.query.sqm.tree.expression.SqmCastTarget) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) TemporalUnit(org.hibernate.query.sqm.TemporalUnit) SqmCollectionSize(org.hibernate.query.sqm.tree.expression.SqmCollectionSize) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) SqlAstQueryPartProcessingState(org.hibernate.sql.ast.spi.SqlAstQueryPartProcessingState) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) Star(org.hibernate.sql.ast.tree.expression.Star) SqmParameter(org.hibernate.query.sqm.tree.expression.SqmParameter) Conversion(org.hibernate.query.sqm.tree.expression.Conversion) SqlTypedMappingImpl(org.hibernate.metamodel.mapping.internal.SqlTypedMappingImpl) SqmJoinType(org.hibernate.query.sqm.tree.SqmJoinType) SqlExpressionResolver.createColumnReferenceKey(org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey) SqmAny(org.hibernate.query.sqm.tree.expression.SqmAny) NonAggregatedCompositeValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.NonAggregatedCompositeValuedPathInterpretation) Distinct(org.hibernate.sql.ast.tree.expression.Distinct) ArrayList(java.util.ArrayList) NullType(org.hibernate.type.NullType) SQLException(java.sql.SQLException) SqmCorrelation(org.hibernate.query.sqm.tree.domain.SqmCorrelation) MULTIPLY(org.hibernate.query.sqm.BinaryArithmeticOperator.MULTIPLY) VersionTypeSeedParameterSpecification(org.hibernate.sql.exec.internal.VersionTypeSeedParameterSpecification) FetchTiming(org.hibernate.engine.FetchTiming) BulkInsertionCapableIdentifierGenerator(org.hibernate.id.BulkInsertionCapableIdentifierGenerator) SqmNullnessPredicate(org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate) EmbeddableDomainType(org.hibernate.metamodel.model.domain.EmbeddableDomainType) SqmExpressionHelper(org.hibernate.query.sqm.tree.expression.SqmExpressionHelper) SqlTreeCreationLogger(org.hibernate.sql.ast.SqlTreeCreationLogger) QueryEngine(org.hibernate.query.spi.QueryEngine) SqmAssignment(org.hibernate.query.sqm.tree.update.SqmAssignment) CollectionClassification(org.hibernate.metamodel.CollectionClassification) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) SqmValues(org.hibernate.query.sqm.tree.insert.SqmValues) SqmJpaCompoundSelection(org.hibernate.query.sqm.tree.select.SqmJpaCompoundSelection) ExecutionContext(org.hibernate.sql.exec.spi.ExecutionContext) SqmCteTable(org.hibernate.query.sqm.tree.cte.SqmCteTable) SqmInsertValuesStatement(org.hibernate.query.sqm.tree.insert.SqmInsertValuesStatement) CteStatement(org.hibernate.sql.ast.tree.cte.CteStatement) Joinable(org.hibernate.persister.entity.Joinable) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) SqmFunction(org.hibernate.query.sqm.tree.expression.SqmFunction) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) EntityAssociationMapping(org.hibernate.metamodel.mapping.EntityAssociationMapping) EmbeddableValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.EmbeddableValuedPathInterpretation) Summarization(org.hibernate.sql.ast.tree.expression.Summarization) DynamicInstantiation(org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiation) SqmMapEntryResult(org.hibernate.query.sqm.sql.internal.SqmMapEntryResult) SqmOrderByClause(org.hibernate.query.sqm.tree.select.SqmOrderByClause) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) TemporalType(jakarta.persistence.TemporalType) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) DomainResult(org.hibernate.sql.results.graph.DomainResult) OrdinalEnumValueConverter(org.hibernate.metamodel.model.convert.internal.OrdinalEnumValueConverter) GroupedPredicate(org.hibernate.sql.ast.tree.predicate.GroupedPredicate) MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) List(java.util.List) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) SyntheticVirtualTableGroup(org.hibernate.sql.ast.tree.from.SyntheticVirtualTableGroup) BasicEntityIdentifierMapping(org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping) QueryLogging(org.hibernate.query.QueryLogging) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) SqmEmptinessPredicate(org.hibernate.query.sqm.tree.predicate.SqmEmptinessPredicate) AbstractSqmSpecificPluralPartPath(org.hibernate.query.sqm.tree.domain.AbstractSqmSpecificPluralPartPath) SqmDynamicInstantiation(org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation) JavaObjectType(org.hibernate.type.JavaObjectType) JdbcParameters(org.hibernate.sql.exec.spi.JdbcParameters) LockMode(org.hibernate.LockMode) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) SqmCteStatement(org.hibernate.query.sqm.tree.cte.SqmCteStatement) EmbeddedCollectionPart(org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart) AbstractSqmSelfRenderingFunctionDescriptor(org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor) TrimSpecification(org.hibernate.sql.ast.tree.expression.TrimSpecification) Every(org.hibernate.sql.ast.tree.expression.Every) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) BasicValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.BasicValuedPathInterpretation) EntityTypeImpl(org.hibernate.metamodel.model.domain.internal.EntityTypeImpl) Format(org.hibernate.sql.ast.tree.expression.Format) SqlExpressible(org.hibernate.metamodel.mapping.SqlExpressible) BaseSemanticQueryWalker(org.hibernate.query.sqm.spi.BaseSemanticQueryWalker) UNARY_MINUS(org.hibernate.query.sqm.UnaryArithmeticOperator.UNARY_MINUS) SqlTypes(org.hibernate.type.SqlTypes) PostInsertIdentifierGenerator(org.hibernate.id.PostInsertIdentifierGenerator) Map(java.util.Map) FetchProfile(org.hibernate.engine.profile.FetchProfile) BigInteger(java.math.BigInteger) SqmSearchClauseSpecification(org.hibernate.query.sqm.tree.cte.SqmSearchClauseSpecification) SqmCorrelatedRootJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedRootJoin) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) AbstractTimeZoneStorageCompositeUserType(org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) InferredBasicValueResolver(org.hibernate.boot.model.process.internal.InferredBasicValueResolver) FetchClauseType(org.hibernate.query.sqm.FetchClauseType) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) PreparedStatement(java.sql.PreparedStatement) SqmQueryPart(org.hibernate.query.sqm.tree.select.SqmQueryPart) SqmJunctionPredicate(org.hibernate.query.sqm.tree.predicate.SqmJunctionPredicate) SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) Overflow(org.hibernate.sql.ast.tree.expression.Overflow) SqlAliasBaseGenerator(org.hibernate.sql.ast.spi.SqlAliasBaseGenerator) QueryOptions(org.hibernate.query.spi.QueryOptions) SqmParameterInterpretation(org.hibernate.query.sqm.sql.internal.SqmParameterInterpretation) SemanticException(org.hibernate.query.SemanticException) SqmIndexAggregateFunction(org.hibernate.query.sqm.tree.domain.SqmIndexAggregateFunction) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) SqmSetClause(org.hibernate.query.sqm.tree.update.SqmSetClause) Type(jakarta.persistence.metamodel.Type) JpaCriteriaParameter(org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) ModelPartContainer(org.hibernate.metamodel.mapping.ModelPartContainer) SqmOver(org.hibernate.query.sqm.tree.expression.SqmOver) SqlTypedMapping(org.hibernate.metamodel.mapping.SqlTypedMapping) EntityGraphTraversalState(org.hibernate.sql.results.graph.EntityGraphTraversalState) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) DomainParameterXref(org.hibernate.query.sqm.internal.DomainParameterXref) DynamicInstantiationNature(org.hibernate.query.sqm.DynamicInstantiationNature) JdbcParametersImpl(org.hibernate.sql.exec.internal.JdbcParametersImpl) EntityPersister(org.hibernate.persister.entity.EntityPersister) SqlAstProcessingStateImpl(org.hibernate.query.sqm.sql.internal.SqlAstProcessingStateImpl) CompositeSqmPathSource(org.hibernate.metamodel.model.domain.internal.CompositeSqmPathSource) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SqmCaseSearched(org.hibernate.query.sqm.tree.expression.SqmCaseSearched) Locale(java.util.Locale) SqmMapEntryReference(org.hibernate.query.sqm.tree.domain.SqmMapEntryReference) SqmOverflow(org.hibernate.query.sqm.tree.expression.SqmOverflow) ComparisonOperator(org.hibernate.query.sqm.ComparisonOperator) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) SqmPredicate(org.hibernate.query.sqm.tree.predicate.SqmPredicate) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) Collection(java.util.Collection) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) SqmBinaryArithmetic(org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic) SqmAnyValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmAnyValuedSimplePath) UpdateStatement(org.hibernate.sql.ast.tree.update.UpdateStatement) EntityTypeLiteral(org.hibernate.sql.ast.tree.expression.EntityTypeLiteral) QueryParameterImplementor(org.hibernate.query.spi.QueryParameterImplementor) SqmExtractUnit(org.hibernate.query.sqm.tree.expression.SqmExtractUnit) SqmCrossJoin(org.hibernate.query.sqm.tree.from.SqmCrossJoin) SqmFrom(org.hibernate.query.sqm.tree.from.SqmFrom) NullnessHelper.coalesceSuppliedValues(org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues) SqmPositionalParameter(org.hibernate.query.sqm.tree.expression.SqmPositionalParameter) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) SqmDynamicInstantiationArgument(org.hibernate.query.sqm.tree.select.SqmDynamicInstantiationArgument) SqmSelectableNode(org.hibernate.query.sqm.tree.select.SqmSelectableNode) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) Logger(org.jboss.logging.Logger) UnaryOperation(org.hibernate.sql.ast.tree.expression.UnaryOperation) SqmParameterizedEntityType(org.hibernate.query.sqm.tree.expression.SqmParameterizedEntityType) SortOrder(org.hibernate.query.sqm.SortOrder) Duration(org.hibernate.sql.ast.tree.expression.Duration) HashSet(java.util.HashSet) SqmNamedParameter(org.hibernate.query.sqm.tree.expression.SqmNamedParameter) BinaryArithmeticOperator(org.hibernate.query.sqm.BinaryArithmeticOperator) SqmByUnit(org.hibernate.query.sqm.tree.expression.SqmByUnit) SqmMemberOfPredicate(org.hibernate.query.sqm.tree.predicate.SqmMemberOfPredicate) Values(org.hibernate.sql.ast.tree.insert.Values) DomainResultProducer(org.hibernate.query.sqm.sql.internal.DomainResultProducer) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) AppliedGraph(org.hibernate.graph.spi.AppliedGraph) QueryGroup(org.hibernate.sql.ast.tree.select.QueryGroup) DiscriminatedAssociationPathInterpretation(org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationPathInterpretation) QueryPartTableReference(org.hibernate.sql.ast.tree.from.QueryPartTableReference) PluralPersistentAttribute(org.hibernate.metamodel.model.domain.PluralPersistentAttribute) AbstractMap(java.util.AbstractMap) SqmInsertStatement(org.hibernate.query.sqm.tree.insert.SqmInsertStatement) SqmPluralPartJoin(org.hibernate.query.sqm.tree.domain.SqmPluralPartJoin) SqmCoalesce(org.hibernate.query.sqm.tree.expression.SqmCoalesce) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) SqmAttributeJoin(org.hibernate.query.sqm.tree.from.SqmAttributeJoin) SqmLikePredicate(org.hibernate.query.sqm.tree.predicate.SqmLikePredicate) Internal(org.hibernate.Internal) SqmStatement(org.hibernate.query.sqm.tree.SqmStatement) SqmPluralValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) SqmExistsPredicate(org.hibernate.query.sqm.tree.predicate.SqmExistsPredicate) SqmEmbeddedValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath) EntityValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.EntityValuedPathInterpretation) PatternRenderer(org.hibernate.query.sqm.produce.function.internal.PatternRenderer) Fetchable(org.hibernate.sql.results.graph.Fetchable) ConvertedQueryLiteral(org.hibernate.sql.ast.tree.expression.ConvertedQueryLiteral) SqmEntityValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath) Set(java.util.Set) Expression(org.hibernate.sql.ast.tree.expression.Expression) NavigablePath(org.hibernate.spi.NavigablePath) SqmTrimSpecification(org.hibernate.query.sqm.tree.expression.SqmTrimSpecification) EmbeddedSqmPathSource(org.hibernate.metamodel.model.domain.internal.EmbeddedSqmPathSource) JpaPath(org.hibernate.query.criteria.JpaPath) ValueMapping(org.hibernate.metamodel.mapping.ValueMapping) SqmPathSource(org.hibernate.query.sqm.SqmPathSource) InsertStatement(org.hibernate.sql.ast.tree.insert.InsertStatement) SqmCollation(org.hibernate.query.sqm.tree.expression.SqmCollation) HibernateException(org.hibernate.HibernateException) QueryException(org.hibernate.QueryException) SqmSelectClause(org.hibernate.query.sqm.tree.select.SqmSelectClause) JdbcLiteral(org.hibernate.sql.ast.tree.expression.JdbcLiteral) SqmLiteralEntityType(org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType) CteContainer(org.hibernate.sql.ast.tree.cte.CteContainer) JavaType(org.hibernate.type.descriptor.java.JavaType) SqmDurationUnit(org.hibernate.query.sqm.tree.expression.SqmDurationUnit) SqmSubQuery(org.hibernate.query.sqm.tree.select.SqmSubQuery) InterpretationException(org.hibernate.query.sqm.InterpretationException) Clause(org.hibernate.sql.ast.Clause) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) BiConsumer(java.util.function.BiConsumer) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) ReturnableType(org.hibernate.query.ReturnableType) DiscriminatorSqmPath(org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath) SqmElementAggregateFunction(org.hibernate.query.sqm.tree.domain.SqmElementAggregateFunction) SqmQueryGroup(org.hibernate.query.sqm.tree.select.SqmQueryGroup) StandardEntityGraphTraversalStateImpl(org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl) SqmWhereClause(org.hibernate.query.sqm.tree.predicate.SqmWhereClause) SqmGroupedPredicate(org.hibernate.query.sqm.tree.predicate.SqmGroupedPredicate) SqmPathInterpretation(org.hibernate.query.sqm.sql.internal.SqmPathInterpretation) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) CollectionHelper(org.hibernate.internal.util.collections.CollectionHelper) CastTarget(org.hibernate.sql.ast.tree.expression.CastTarget) SqmEntityJoin(org.hibernate.query.sqm.tree.from.SqmEntityJoin) SqmInListPredicate(org.hibernate.query.sqm.tree.predicate.SqmInListPredicate) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate) TypeConfiguration.isDuration(org.hibernate.type.spi.TypeConfiguration.isDuration) SqmUpdateStatement(org.hibernate.query.sqm.tree.update.SqmUpdateStatement) EnumJavaType(org.hibernate.type.descriptor.java.EnumJavaType) SqmDeleteStatement(org.hibernate.query.sqm.tree.delete.SqmDeleteStatement) IdentityHashMap(java.util.IdentityHashMap) NullnessPredicate(org.hibernate.sql.ast.tree.predicate.NullnessPredicate) SqmBetweenPredicate(org.hibernate.query.sqm.tree.predicate.SqmBetweenPredicate) SimpleDomainType(org.hibernate.metamodel.model.domain.SimpleDomainType) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) BooleanExpressionPredicate(org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate) Over(org.hibernate.sql.ast.tree.expression.Over) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) DurationUnit(org.hibernate.sql.ast.tree.expression.DurationUnit) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) Collation(org.hibernate.sql.ast.tree.expression.Collation) SqlTupleContainer(org.hibernate.sql.ast.tree.expression.SqlTupleContainer) InListPredicate(org.hibernate.sql.ast.tree.predicate.InListPredicate) Junction(org.hibernate.sql.ast.tree.predicate.Junction) SelectableMappings(org.hibernate.metamodel.mapping.SelectableMappings) SqmDistinct(org.hibernate.query.sqm.tree.expression.SqmDistinct) SqmInSubQueryPredicate(org.hibernate.query.sqm.tree.predicate.SqmInSubQueryPredicate) HashMap(java.util.HashMap) SqmLiteral(org.hibernate.query.sqm.tree.expression.SqmLiteral) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification) CteColumn(org.hibernate.sql.ast.tree.cte.CteColumn) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) Iterator(java.util.Iterator) EmbeddableMappingType(org.hibernate.metamodel.mapping.EmbeddableMappingType) SqmStar(org.hibernate.query.sqm.tree.expression.SqmStar) SqmSelection(org.hibernate.query.sqm.tree.select.SqmSelection) SqmQuerySource(org.hibernate.query.sqm.SqmQuerySource) SqmTypedNode(org.hibernate.query.sqm.tree.SqmTypedNode) SelectClause(org.hibernate.sql.ast.tree.select.SelectClause) Association(org.hibernate.metamodel.mapping.Association) CastType(org.hibernate.query.sqm.CastType) SqmCteTableColumn(org.hibernate.query.sqm.tree.cte.SqmCteTableColumn) SqmMappingModelHelper(org.hibernate.query.sqm.internal.SqmMappingModelHelper) QueryPart(org.hibernate.sql.ast.tree.select.QueryPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) Stack(org.hibernate.internal.util.collections.Stack) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) Collections(java.util.Collections) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) NavigablePath(org.hibernate.spi.NavigablePath) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) SqmTreatedPath(org.hibernate.query.sqm.tree.domain.SqmTreatedPath) TableReference(org.hibernate.sql.ast.tree.from.TableReference) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) QueryPartTableReference(org.hibernate.sql.ast.tree.from.QueryPartTableReference) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) EmbeddedCollectionPart(org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) EmbeddableValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.EmbeddableValuedPathInterpretation) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) SyntheticVirtualTableGroup(org.hibernate.sql.ast.tree.from.SyntheticVirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) BasicValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.BasicValuedPathInterpretation) SqmRoot(org.hibernate.query.sqm.tree.from.SqmRoot) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmFkExpression(org.hibernate.query.sqm.tree.domain.SqmFkExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) BasicEntityIdentifierMapping(org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) ModelPartContainer(org.hibernate.metamodel.mapping.ModelPartContainer) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 9 with ModelPart

use of org.hibernate.metamodel.mapping.ModelPart in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method createLateralJoinExpression.

protected Expression createLateralJoinExpression(AbstractSqmSpecificPluralPartPath<?> pluralPartPath, boolean index, String functionName) {
    prepareReusablePath(pluralPartPath.getLhs(), () -> null);
    final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) determineValueMapping(pluralPartPath.getPluralDomainPath());
    final FromClauseAccess parentFromClauseAccess = getFromClauseAccess();
    final TableGroup parentTableGroup = parentFromClauseAccess.findTableGroup(pluralPartPath.getNavigablePath().getParent());
    final CollectionPart collectionPart = index ? pluralAttributeMapping.getIndexDescriptor() : pluralAttributeMapping.getElementDescriptor();
    final ModelPart modelPart;
    if (collectionPart instanceof EntityAssociationMapping) {
        modelPart = ((EntityAssociationMapping) collectionPart).getKeyTargetMatchPart();
    } else {
        modelPart = collectionPart;
    }
    final int jdbcTypeCount = modelPart.getJdbcTypeCount();
    final String pathName = functionName + (index ? "_index" : "_element");
    final String identifierVariable = parentTableGroup.getPrimaryTableReference().getIdentificationVariable() + "_" + pathName;
    final NavigablePath queryPath = new NavigablePath(parentTableGroup.getNavigablePath(), pathName, identifierVariable);
    TableGroup lateralTableGroup = parentFromClauseAccess.findTableGroup(queryPath);
    if (lateralTableGroup == null) {
        final QuerySpec subQuerySpec = new QuerySpec(false);
        pushProcessingState(new SqlAstQueryPartProcessingStateImpl(subQuerySpec, getCurrentProcessingState(), this, currentClauseStack::getCurrent, false));
        try {
            final TableGroup tableGroup = pluralAttributeMapping.createRootTableGroup(true, pluralPartPath.getNavigablePath(), null, () -> subQuerySpec::applyPredicate, this, creationContext);
            pluralAttributeMapping.applyBaseRestrictions(subQuerySpec::applyPredicate, tableGroup, true, getLoadQueryInfluencers().getEnabledFilters(), null, this);
            getFromClauseAccess().registerTableGroup(pluralPartPath.getNavigablePath(), tableGroup);
            registerPluralTableGroupParts(tableGroup);
            subQuerySpec.getFromClause().addRoot(tableGroup);
            final List<String> columnNames = new ArrayList<>(jdbcTypeCount);
            final List<ColumnReference> resultColumnReferences = new ArrayList<>(jdbcTypeCount);
            final NavigablePath navigablePath = pluralPartPath.getNavigablePath();
            final Boolean max = functionName.equalsIgnoreCase("max") ? Boolean.TRUE : (functionName.equalsIgnoreCase("min") ? Boolean.FALSE : null);
            final AbstractSqmSelfRenderingFunctionDescriptor functionDescriptor = (AbstractSqmSelfRenderingFunctionDescriptor) creationContext.getSessionFactory().getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(functionName);
            final List<ColumnReference> subQueryColumns = new ArrayList<>(jdbcTypeCount);
            modelPart.forEachSelectable((selectionIndex, selectionMapping) -> {
                final ColumnReference columnReference = new ColumnReference(tableGroup.resolveTableReference(navigablePath, selectionMapping.getContainingTableExpression()), selectionMapping, creationContext.getSessionFactory());
                final String columnName;
                if (selectionMapping.isFormula()) {
                    columnName = "col" + columnNames.size();
                } else {
                    columnName = selectionMapping.getSelectionExpression();
                }
                columnNames.add(columnName);
                subQueryColumns.add(columnReference);
                if (max != null) {
                    subQuerySpec.addSortSpecification(new SortSpecification(columnReference, max ? SortOrder.DESCENDING : SortOrder.ASCENDING));
                }
            });
            if (max != null) {
                for (int i = 0; i < subQueryColumns.size(); i++) {
                    subQuerySpec.getSelectClause().addSqlSelection(new SqlSelectionImpl(i + 1, i, subQueryColumns.get(i)));
                    resultColumnReferences.add(new ColumnReference(identifierVariable, columnNames.get(i), false, null, null, subQueryColumns.get(i).getJdbcMapping(), creationContext.getSessionFactory()));
                }
                subQuerySpec.setFetchClauseExpression(new QueryLiteral<>(1, basicType(Integer.class)), FetchClauseType.ROWS_ONLY);
            } else {
                final List<? extends SqlAstNode> arguments;
                if (jdbcTypeCount == 1) {
                    arguments = subQueryColumns;
                } else {
                    arguments = Collections.singletonList(new SqlTuple(subQueryColumns, modelPart));
                }
                final Expression expression = new SelfRenderingAggregateFunctionSqlAstExpression(functionDescriptor.getName(), functionDescriptor, arguments, null, (ReturnableType<?>) functionDescriptor.getReturnTypeResolver().resolveFunctionReturnType(() -> null, arguments).getJdbcMapping(), modelPart);
                subQuerySpec.getSelectClause().addSqlSelection(new SqlSelectionImpl(1, 0, expression));
                resultColumnReferences.add(new ColumnReference(identifierVariable, columnNames.get(0), false, null, null, expression.getExpressionType().getJdbcMappings().get(0), creationContext.getSessionFactory()));
            }
            subQuerySpec.applyPredicate(pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(parentFromClauseAccess.findTableGroup(pluralPartPath.getPluralDomainPath().getNavigablePath().getParent()), tableGroup, getSqlExpressionResolver(), creationContext));
            final String compatibleTableExpression;
            if (modelPart instanceof BasicValuedModelPart) {
                compatibleTableExpression = ((BasicValuedModelPart) modelPart).getContainingTableExpression();
            } else if (modelPart instanceof EmbeddableValuedModelPart) {
                compatibleTableExpression = ((EmbeddableValuedModelPart) modelPart).getContainingTableExpression();
            } else {
                compatibleTableExpression = null;
            }
            lateralTableGroup = new QueryPartTableGroup(queryPath, null, subQuerySpec, identifierVariable, columnNames, compatibleTableExpression, true, false, creationContext.getSessionFactory());
            if (currentlyProcessingJoin == null) {
                parentTableGroup.addTableGroupJoin(new TableGroupJoin(lateralTableGroup.getNavigablePath(), SqlAstJoinType.LEFT, lateralTableGroup));
            } else {
                // In case this is used in the ON condition, we must prepend this lateral join
                final TableGroup targetTableGroup;
                if (currentlyProcessingJoin.getLhs() == null) {
                    targetTableGroup = parentFromClauseAccess.getTableGroup(currentlyProcessingJoin.findRoot().getNavigablePath());
                } else {
                    targetTableGroup = parentFromClauseAccess.getTableGroup(currentlyProcessingJoin.getLhs().getNavigablePath());
                }
                // Many databases would support modelling this as nested table group join,
                // but at least SQL Server doesn't like that, saying that the correlated columns can't be "bound"
                // Since there is no dependency on the currentlyProcessingJoin, we can safely prepend this join
                targetTableGroup.prependTableGroupJoin(currentlyProcessingJoin.getNavigablePath(), new TableGroupJoin(lateralTableGroup.getNavigablePath(), SqlAstJoinType.LEFT, lateralTableGroup));
            }
            parentFromClauseAccess.registerTableGroup(lateralTableGroup.getNavigablePath(), lateralTableGroup);
            if (jdbcTypeCount == 1) {
                return new SelfRenderingFunctionSqlAstExpression(pathName, (sqlAppender, sqlAstArguments, walker) -> {
                    sqlAstArguments.get(0).accept(walker);
                }, resultColumnReferences, (ReturnableType<?>) resultColumnReferences.get(0).getJdbcMapping(), resultColumnReferences.get(0).getJdbcMapping());
            } else {
                return new SqlTuple(resultColumnReferences, modelPart);
            }
        } finally {
            popProcessingStateStack();
        }
    }
    final QueryPartTableReference tableReference = (QueryPartTableReference) lateralTableGroup.getPrimaryTableReference();
    if (jdbcTypeCount == 1) {
        final List<SqlSelection> sqlSelections = tableReference.getQueryPart().getFirstQuerySpec().getSelectClause().getSqlSelections();
        return new SelfRenderingFunctionSqlAstExpression(pathName, (sqlAppender, sqlAstArguments, walker) -> {
            sqlAstArguments.get(0).accept(walker);
        }, Collections.singletonList(new ColumnReference(identifierVariable, tableReference.getColumnNames().get(0), false, null, null, sqlSelections.get(0).getExpressionType().getJdbcMappings().get(0), creationContext.getSessionFactory())), (ReturnableType<?>) sqlSelections.get(0).getExpressionType().getJdbcMappings().get(0), sqlSelections.get(0).getExpressionType());
    } else {
        final List<ColumnReference> resultColumnReferences = new ArrayList<>(jdbcTypeCount);
        modelPart.forEachSelectable((selectionIndex, selectionMapping) -> resultColumnReferences.add(new ColumnReference(identifierVariable, tableReference.getColumnNames().get(selectionIndex), false, null, null, selectionMapping.getJdbcMapping(), creationContext.getSessionFactory())));
        return new SqlTuple(resultColumnReferences, modelPart);
    }
}
Also used : SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) NavigablePath(org.hibernate.spi.NavigablePath) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ArrayList(java.util.ArrayList) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) AbstractSqmSelfRenderingFunctionDescriptor(org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) SqlAstQueryPartProcessingStateImpl(org.hibernate.query.sqm.sql.internal.SqlAstQueryPartProcessingStateImpl) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) EmbeddedCollectionPart(org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) SyntheticVirtualTableGroup(org.hibernate.sql.ast.tree.from.SyntheticVirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) EntityAssociationMapping(org.hibernate.metamodel.mapping.EntityAssociationMapping) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmFkExpression(org.hibernate.query.sqm.tree.domain.SqmFkExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) SqlSelectionImpl(org.hibernate.sql.results.internal.SqlSelectionImpl) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) QueryPartTableReference(org.hibernate.sql.ast.tree.from.QueryPartTableReference) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 10 with ModelPart

use of org.hibernate.metamodel.mapping.ModelPart in project hibernate-orm by hibernate.

the class EntityValuedPathInterpretation method from.

public static <T> EntityValuedPathInterpretation<T> from(NavigablePath navigablePath, TableGroup tableGroup, ModelPart resultModelPart, EntityValuedModelPart mapping, EntityValuedModelPart treatedMapping, SqmToSqlAstConverter sqlAstCreationState) {
    final SqlExpressionResolver sqlExprResolver = sqlAstCreationState.getSqlExpressionResolver();
    final SessionFactoryImplementor sessionFactory = sqlAstCreationState.getCreationContext().getSessionFactory();
    final Expression sqlExpression;
    if (resultModelPart == null) {
        final EntityMappingType entityMappingType = mapping.getEntityMappingType();
        final EntityIdentifierMapping identifierMapping = entityMappingType.getIdentifierMapping();
        final EntityDiscriminatorMapping discriminatorMapping = entityMappingType.getDiscriminatorMapping();
        final List<Expression> expressions = new ArrayList<>(entityMappingType.getJdbcTypeCount() + identifierMapping.getJdbcTypeCount() + (discriminatorMapping == null ? 0 : 1));
        final TableGroup parentTableGroup = tableGroup;
        final SelectableConsumer selectableConsumer = (selectionIndex, selectableMapping) -> {
            final TableReference tableReference = parentTableGroup.resolveTableReference(navigablePath, selectableMapping.getContainingTableExpression(), false);
            expressions.add(sqlExprResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, selectableMapping.getSelectionExpression()), processingState -> new ColumnReference(tableReference, selectableMapping, sessionFactory)));
        };
        identifierMapping.forEachSelectable(selectableConsumer);
        if (discriminatorMapping != null) {
            discriminatorMapping.forEachSelectable(selectableConsumer);
        }
        entityMappingType.forEachSelectable(selectableConsumer);
        sqlExpression = new SqlTuple(expressions, entityMappingType);
    } else {
        if (resultModelPart instanceof BasicValuedModelPart) {
            final BasicValuedModelPart basicValuedModelPart = (BasicValuedModelPart) resultModelPart;
            final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, basicValuedModelPart.getContainingTableExpression());
            sqlExpression = sqlExprResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, basicValuedModelPart.getSelectionExpression()), processingState -> new ColumnReference(tableReference, basicValuedModelPart, sessionFactory));
        } else {
            final List<Expression> expressions = new ArrayList<>(resultModelPart.getJdbcTypeCount());
            resultModelPart.forEachSelectable((selectionIndex, selectableMapping) -> {
                final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, selectableMapping.getContainingTableExpression());
                expressions.add(sqlExprResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, selectableMapping.getSelectionExpression()), processingState -> new ColumnReference(tableReference, selectableMapping, sessionFactory)));
            });
            sqlExpression = new SqlTuple(expressions, resultModelPart);
        }
    }
    return new EntityValuedPathInterpretation<>(sqlExpression, navigablePath, tableGroup, treatedMapping);
}
Also used : BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) SqlTupleContainer(org.hibernate.sql.ast.tree.expression.SqlTupleContainer) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) ArrayList(java.util.ArrayList) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EntityAssociationMapping(org.hibernate.metamodel.mapping.EntityAssociationMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Assignable(org.hibernate.sql.ast.tree.update.Assignable) SqmEntityValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath) Expression(org.hibernate.sql.ast.tree.expression.Expression) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping) SqmToSqlAstConverter(org.hibernate.query.sqm.sql.SqmToSqlAstConverter) NavigablePath(org.hibernate.spi.NavigablePath) SqlAstWalker(org.hibernate.sql.ast.SqlAstWalker) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) Consumer(java.util.function.Consumer) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) List(java.util.List) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) Collections(java.util.Collections) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlExpressionResolver.createColumnReferenceKey(org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping) TableReference(org.hibernate.sql.ast.tree.from.TableReference) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) Expression(org.hibernate.sql.ast.tree.expression.Expression) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Aggregations

ModelPart (org.hibernate.metamodel.mapping.ModelPart)45 BasicValuedModelPart (org.hibernate.metamodel.mapping.BasicValuedModelPart)21 EmbeddableValuedModelPart (org.hibernate.metamodel.mapping.EmbeddableValuedModelPart)21 EntityValuedModelPart (org.hibernate.metamodel.mapping.EntityValuedModelPart)16 EntityPersister (org.hibernate.persister.entity.EntityPersister)15 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)15 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)14 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)13 ForeignKeyDescriptor (org.hibernate.metamodel.mapping.ForeignKeyDescriptor)13 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)13 NavigablePath (org.hibernate.spi.NavigablePath)13 ArrayList (java.util.ArrayList)12 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)11 Test (org.junit.jupiter.api.Test)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)9 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)9 Expression (org.hibernate.sql.ast.tree.expression.Expression)9 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)9 NotYetImplementedFor6Exception (org.hibernate.NotYetImplementedFor6Exception)8 ConvertibleModelPart (org.hibernate.metamodel.mapping.ConvertibleModelPart)8