Search in sources :

Example 31 with TableGroupJoin

use of org.hibernate.sql.ast.tree.from.TableGroupJoin in project hibernate-orm by hibernate.

the class DynamicFetchBuilderLegacy method buildFetch.

@Override
public Fetch buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationState = ResultsHelper.impl(domainResultCreationState);
    final TableGroup ownerTableGroup = creationState.getFromClauseAccess().findByAlias(ownerTableAlias);
    final AttributeMapping attributeMapping = parent.getReferencedMappingContainer().findContainingEntityMapping().findDeclaredAttributeMapping(fetchableName);
    final TableGroup tableGroup;
    if (attributeMapping instanceof TableGroupJoinProducer) {
        final SqlAliasBase sqlAliasBase = new SqlAliasBaseConstant(tableAlias);
        final TableGroupJoin tableGroupJoin = ((TableGroupJoinProducer) attributeMapping).createTableGroupJoin(fetchPath, ownerTableGroup, tableAlias, SqlAstJoinType.INNER, true, false, s -> sqlAliasBase, creationState.getSqlExpressionResolver(), creationState.getFromClauseAccess(), creationState.getCreationContext());
        ownerTableGroup.addTableGroupJoin(tableGroupJoin);
        creationState.getFromClauseAccess().registerTableGroup(fetchPath, tableGroup = tableGroupJoin.getJoinedGroup());
    } else {
        tableGroup = ownerTableGroup;
    }
    if (columnNames != null) {
        final ForeignKeyDescriptor keyDescriptor;
        if (attributeMapping instanceof PluralAttributeMapping) {
            final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) attributeMapping;
            keyDescriptor = pluralAttributeMapping.getKeyDescriptor();
        } else {
            // Not sure if this fetch builder can also be used with other attribute mappings
            assert attributeMapping instanceof ToOneAttributeMapping;
            final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
            keyDescriptor = toOneAttributeMapping.getForeignKeyDescriptor();
        }
        if (!columnNames.isEmpty()) {
            keyDescriptor.forEachSelectable((selectionIndex, selectableMapping) -> {
                resolveSqlSelection(columnNames.get(selectionIndex), createColumnReferenceKey(tableGroup.resolveTableReference(selectableMapping.getContainingTableExpression()), selectableMapping.getSelectionExpression()), selectableMapping.getJdbcMapping(), jdbcResultsMetadata, domainResultCreationState);
            });
        }
        // We process the fetch builder such that it contains a resultBuilderEntity before calling this method in ResultSetMappingProcessor
        if (resultBuilderEntity != null) {
            return resultBuilderEntity.buildFetch(parent, attributeMapping, jdbcResultsMetadata, creationState);
        }
    }
    try {
        final NavigablePath currentRelativePath = creationState.getCurrentRelativePath();
        final String prefix;
        if (currentRelativePath == null) {
            prefix = "";
        } else {
            prefix = currentRelativePath.getFullPath().replace(ELEMENT_PREFIX, "").replace(INDEX_PREFIX, "") + ".";
        }
        creationState.pushExplicitFetchMementoResolver(relativePath -> {
            if (relativePath.startsWith(prefix)) {
                return findFetchBuilder(relativePath.substring(prefix.length()));
            }
            return null;
        });
        return parent.generateFetchableFetch(attributeMapping, parent.resolveNavigablePath(attributeMapping), FetchTiming.IMMEDIATE, true, null, domainResultCreationState);
    } finally {
        creationState.popExplicitFetchMementoResolver();
    }
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) NavigablePath(org.hibernate.query.spi.NavigablePath) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) SqlAliasBaseConstant(org.hibernate.sql.ast.spi.SqlAliasBaseConstant) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase)

Example 32 with TableGroupJoin

use of org.hibernate.sql.ast.tree.from.TableGroupJoin in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method createTableGroup.

private TableGroup createTableGroup(TableGroup parentTableGroup, SqmPath<?> joinedPath) {
    final TableGroup actualParentTableGroup = findActualTableGroup(parentTableGroup, joinedPath);
    final SqmPath<?> lhsPath = joinedPath.getLhs();
    final FromClauseIndex fromClauseIndex = getFromClauseIndex();
    final ModelPart subPart = actualParentTableGroup.getModelPart().findSubPart(joinedPath.getReferencedPathSource().getPathName(), lhsPath instanceof SqmTreatedPath ? resolveEntityPersister(((SqmTreatedPath<?, ?>) lhsPath).getTreatTarget()) : null);
    final TableGroup tableGroup;
    if (subPart instanceof TableGroupJoinProducer) {
        final TableGroupJoinProducer joinProducer = (TableGroupJoinProducer) subPart;
        if (fromClauseIndex.findTableGroup(actualParentTableGroup.getNavigablePath()) == null) {
            final QuerySpec querySpec = currentQuerySpec();
            // The parent table group is on a parent query, so we need a root table group
            tableGroup = joinProducer.createRootTableGroupJoin(joinedPath.getNavigablePath(), actualParentTableGroup, null, null, false, querySpec::applyPredicate, this);
            // Force initialization of a possible lazy table group
            tableGroup.getPrimaryTableReference();
            querySpec.getFromClause().addRoot(tableGroup);
        } else {
            // Check if we can reuse a table group join of the parent
            final TableGroup compatibleTableGroup = findCompatibleJoinedGroup(actualParentTableGroup, joinProducer, SqlAstJoinType.INNER);
            if (compatibleTableGroup == null) {
                final TableGroupJoin tableGroupJoin = joinProducer.createTableGroupJoin(joinedPath.getNavigablePath(), actualParentTableGroup, null, null, false, false, this);
                // Implicit joins in the ON clause of attribute joins need to be added as nested table group joins
                // We don't have to do that for entity joins etc. as these do not have an inherent dependency on the lhs.
                // We can just add the implicit join before the currently processing join
                // See consumeEntityJoin for details
                final boolean nested = currentClauseStack.getCurrent() == Clause.FROM && currentlyProcessingJoin instanceof SqmAttributeJoin<?, ?>;
                if (nested) {
                    actualParentTableGroup.addNestedTableGroupJoin(tableGroupJoin);
                } else {
                    actualParentTableGroup.addTableGroupJoin(tableGroupJoin);
                }
                tableGroup = tableGroupJoin.getJoinedGroup();
            } else {
                tableGroup = compatibleTableGroup;
            }
        }
        fromClauseIndex.register(joinedPath, tableGroup);
        registerPluralTableGroupParts(tableGroup);
    } else {
        tableGroup = null;
    }
    return tableGroup;
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) 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) SqmTreatedPath(org.hibernate.query.sqm.tree.domain.SqmTreatedPath) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec)

Example 33 with TableGroupJoin

use of org.hibernate.sql.ast.tree.from.TableGroupJoin in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method consumeCrossJoin.

private TableGroup consumeCrossJoin(SqmCrossJoin<?> sqmJoin, TableGroup lhsTableGroup, boolean transitive) {
    final EntityPersister entityDescriptor = resolveEntityPersister(sqmJoin.getReferencedPathSource());
    final TableGroup tableGroup = entityDescriptor.createRootTableGroup(true, sqmJoin.getNavigablePath(), sqmJoin.getExplicitAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, predicate), this, getCreationContext());
    final TableGroupJoin tableGroupJoin = new TableGroupJoin(sqmJoin.getNavigablePath(), SqlAstJoinType.CROSS, tableGroup);
    lhsTableGroup.addTableGroupJoin(tableGroupJoin);
    getFromClauseIndex().register(sqmJoin, tableGroup);
    if (transitive) {
        consumeExplicitJoins(sqmJoin, tableGroupJoin.getJoinedGroup());
    }
    return tableGroup;
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup)

Example 34 with TableGroupJoin

use of org.hibernate.sql.ast.tree.from.TableGroupJoin in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method consumeFromClauseCorrelatedRoot.

protected void consumeFromClauseCorrelatedRoot(SqmRoot<?> sqmRoot) {
    log.tracef("Resolving SqmRoot [%s] to TableGroup", sqmRoot);
    final FromClauseIndex fromClauseIndex = getFromClauseIndex();
    if (fromClauseIndex.isResolved(sqmRoot)) {
        log.tracef("Already resolved SqmRoot [%s] to TableGroup", sqmRoot);
    }
    final QuerySpec currentQuerySpec = currentQuerySpec();
    final TableGroup tableGroup;
    if (!sqmRoot.isCorrelated()) {
        return;
    }
    final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory();
    if (sqmRoot.containsOnlyInnerJoins()) {
        // If we have just inner joins against a correlated root, we can render the joins as references
        final SqmFrom<?, ?> from;
        // It will always contain just a single correlated join though, which is what is actually correlated
        if (sqmRoot instanceof SqmCorrelatedRootJoin<?>) {
            assert sqmRoot.getSqmJoins().size() == 1;
            assert sqmRoot.getSqmJoins().get(0).isCorrelated();
            from = sqmRoot.getSqmJoins().get(0);
        } else {
            from = sqmRoot;
        }
        final TableGroup parentTableGroup = fromClauseIndex.findTableGroupOnParents(from.getCorrelationParent().getNavigablePath());
        final SqlAliasBase sqlAliasBase = sqlAliasBaseManager.createSqlAliasBase(parentTableGroup.getGroupAlias());
        if (parentTableGroup instanceof PluralTableGroup) {
            final PluralTableGroup pluralTableGroup = (PluralTableGroup) parentTableGroup;
            final CorrelatedPluralTableGroup correlatedPluralTableGroup = new CorrelatedPluralTableGroup(parentTableGroup, sqlAliasBase, currentQuerySpec, predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, predicate), sessionFactory);
            final TableGroup elementTableGroup = pluralTableGroup.getElementTableGroup();
            if (elementTableGroup != null) {
                final TableGroup correlatedElementTableGroup = new CorrelatedTableGroup(elementTableGroup, sqlAliasBase, currentQuerySpec, predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, predicate), sessionFactory);
                final TableGroupJoin tableGroupJoin = new TableGroupJoin(elementTableGroup.getNavigablePath(), SqlAstJoinType.INNER, correlatedElementTableGroup);
                correlatedPluralTableGroup.registerElementTableGroup(tableGroupJoin);
            }
            final TableGroup indexTableGroup = pluralTableGroup.getIndexTableGroup();
            if (indexTableGroup != null) {
                final TableGroup correlatedIndexTableGroup = new CorrelatedTableGroup(indexTableGroup, sqlAliasBase, currentQuerySpec, predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, predicate), sessionFactory);
                final TableGroupJoin tableGroupJoin = new TableGroupJoin(indexTableGroup.getNavigablePath(), SqlAstJoinType.INNER, correlatedIndexTableGroup);
                correlatedPluralTableGroup.registerIndexTableGroup(tableGroupJoin);
            }
            tableGroup = correlatedPluralTableGroup;
        } else {
            tableGroup = new CorrelatedTableGroup(parentTableGroup, sqlAliasBase, currentQuerySpec, predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, predicate), sessionFactory);
        }
        fromClauseIndex.register(from, tableGroup);
        registerPluralTableGroupParts(tableGroup);
        log.tracef("Resolved SqmRoot [%s] to correlated TableGroup [%s]", sqmRoot, tableGroup);
        consumeExplicitJoins(from, tableGroup);
        return;
    } else {
        final EntityPersister entityDescriptor = resolveEntityPersister(sqmRoot.getReferencedPathSource());
        final TableGroup parentTableGroup = fromClauseIndex.findTableGroupOnParents(sqmRoot.getCorrelationParent().getNavigablePath());
        // If we have non-inner joins against a correlated root, we must render the root with a correlation predicate
        tableGroup = entityDescriptor.createRootTableGroup(true, sqmRoot.getNavigablePath(), sqmRoot.getExplicitAlias(), () -> predicate -> {
        }, this, creationContext);
        final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
        final NavigablePath navigablePath = sqmRoot.getNavigablePath().append(identifierMapping.getNavigableRole().getNavigableName());
        final int jdbcTypeCount = identifierMapping.getJdbcTypeCount();
        if (jdbcTypeCount == 1) {
            identifierMapping.forEachSelectable((index, selectable) -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, new ComparisonPredicate(new ColumnReference(parentTableGroup.resolveTableReference(navigablePath, selectable.getContainingTableExpression()), selectable, sessionFactory), ComparisonOperator.EQUAL, new ColumnReference(tableGroup.resolveTableReference(navigablePath, selectable.getContainingTableExpression()), selectable, sessionFactory))));
        } else {
            final List<Expression> lhs = new ArrayList<>(jdbcTypeCount);
            final List<Expression> rhs = new ArrayList<>(jdbcTypeCount);
            identifierMapping.forEachSelectable((index, selectable) -> {
                lhs.add(new ColumnReference(parentTableGroup.resolveTableReference(navigablePath, selectable.getContainingTableExpression()), selectable, sessionFactory));
                rhs.add(new ColumnReference(tableGroup.resolveTableReference(navigablePath, selectable.getContainingTableExpression()), selectable, sessionFactory));
            });
            additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, new ComparisonPredicate(new SqlTuple(lhs, identifierMapping), ComparisonOperator.EQUAL, new SqlTuple(rhs, identifierMapping)));
        }
    }
    log.tracef("Resolved SqmRoot [%s] to new TableGroup [%s]", sqmRoot, tableGroup);
    fromClauseIndex.register(sqmRoot, tableGroup);
    currentQuerySpec.getFromClause().addRoot(tableGroup);
    consumeJoins(sqmRoot, fromClauseIndex, tableGroup);
}
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) Format(org.hibernate.sql.ast.tree.expression.Format) SqlExpressible(org.hibernate.metamodel.mapping.SqlExpressible) SqmFieldLiteral(org.hibernate.query.sqm.tree.expression.SqmFieldLiteral) BasicType(org.hibernate.type.BasicType) MultipleBagFetchException(org.hibernate.loader.MultipleBagFetchException) BaseSemanticQueryWalker(org.hibernate.query.sqm.spi.BaseSemanticQueryWalker) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) UNARY_MINUS(org.hibernate.query.sqm.UnaryArithmeticOperator.UNARY_MINUS) SqlTypes(org.hibernate.type.SqlTypes) JdbcMappingContainer(org.hibernate.metamodel.mapping.JdbcMappingContainer) SelfInterpretingSqmPath(org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath) PostInsertIdentifierGenerator(org.hibernate.id.PostInsertIdentifierGenerator) Map(java.util.Map) FetchProfile(org.hibernate.engine.profile.FetchProfile) BigInteger(java.math.BigInteger) EntityVersionMapping(org.hibernate.metamodel.mapping.EntityVersionMapping) PluralValuedSimplePathInterpretation(org.hibernate.query.sqm.sql.internal.PluralValuedSimplePathInterpretation) SqmSearchClauseSpecification(org.hibernate.query.sqm.tree.cte.SqmSearchClauseSpecification) SqmCorrelatedRootJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedRootJoin) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) InSubQueryPredicate(org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate) JdbcType(org.hibernate.type.descriptor.jdbc.JdbcType) InferredBasicValueResolver(org.hibernate.boot.model.process.internal.InferredBasicValueResolver) SqmSummarization(org.hibernate.query.sqm.tree.expression.SqmSummarization) FetchClauseType(org.hibernate.query.sqm.FetchClauseType) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) Optimizer(org.hibernate.id.enhanced.Optimizer) NavigablePath(org.hibernate.query.spi.NavigablePath) AbstractSqlAstTranslator(org.hibernate.sql.ast.spi.AbstractSqlAstTranslator) PreparedStatement(java.sql.PreparedStatement) SqmBooleanExpressionPredicate(org.hibernate.query.sqm.tree.predicate.SqmBooleanExpressionPredicate) SqmQueryPart(org.hibernate.query.sqm.tree.select.SqmQueryPart) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) StandardStack(org.hibernate.internal.util.collections.StandardStack) SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) SqmCteContainer(org.hibernate.query.sqm.tree.cte.SqmCteContainer) SqmJoin(org.hibernate.query.sqm.tree.from.SqmJoin) Overflow(org.hibernate.sql.ast.tree.expression.Overflow) 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) SqlAliasBaseGenerator(org.hibernate.sql.ast.spi.SqlAliasBaseGenerator) FilterHelper(org.hibernate.internal.FilterHelper) QueryOptions(org.hibernate.query.spi.QueryOptions) SqmParameterInterpretation(org.hibernate.query.sqm.sql.internal.SqmParameterInterpretation) 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) SemanticException(org.hibernate.query.SemanticException) JdbcParameterBindings(org.hibernate.sql.exec.spi.JdbcParameterBindings) SqmIndexAggregateFunction(org.hibernate.query.sqm.tree.domain.SqmIndexAggregateFunction) LinkedHashMap(java.util.LinkedHashMap) CteTable(org.hibernate.sql.ast.tree.cte.CteTable) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) BasicSqmPathSource(org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource) SqmTuple(org.hibernate.query.sqm.tree.expression.SqmTuple) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) BasicDomainType(org.hibernate.metamodel.model.domain.BasicDomainType) SqmSetClause(org.hibernate.query.sqm.tree.update.SqmSetClause) 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) JpaCriteriaParameter(org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter) SqmVisitableNode(org.hibernate.query.sqm.tree.SqmVisitableNode) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) DeleteStatement(org.hibernate.sql.ast.tree.delete.DeleteStatement) ModelPartContainer(org.hibernate.metamodel.mapping.ModelPartContainer) QueryParameterBindings(org.hibernate.query.spi.QueryParameterBindings) SqmOver(org.hibernate.query.sqm.tree.expression.SqmOver) LikePredicate(org.hibernate.sql.ast.tree.predicate.LikePredicate) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping) QueryLiteral(org.hibernate.sql.ast.tree.expression.QueryLiteral) SqlTypedMapping(org.hibernate.metamodel.mapping.SqlTypedMapping) Fetch(org.hibernate.sql.results.graph.Fetch) EntityGraphTraversalState(org.hibernate.sql.results.graph.EntityGraphTraversalState) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) 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) DomainParameterXref(org.hibernate.query.sqm.internal.DomainParameterXref) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) DynamicInstantiationNature(org.hibernate.query.sqm.DynamicInstantiationNature) JdbcParametersImpl(org.hibernate.sql.exec.internal.JdbcParametersImpl) UserVersionType(org.hibernate.usertype.UserVersionType) Bindable(org.hibernate.metamodel.mapping.Bindable) EntityPersister(org.hibernate.persister.entity.EntityPersister) SqlAstProcessingStateImpl(org.hibernate.query.sqm.sql.internal.SqlAstProcessingStateImpl) PredicateCollector(org.hibernate.sql.ast.tree.predicate.PredicateCollector) ADD(org.hibernate.query.sqm.BinaryArithmeticOperator.ADD) TimestampdiffFunction(org.hibernate.dialect.function.TimestampdiffFunction) CompositeSqmPathSource(org.hibernate.metamodel.model.domain.internal.CompositeSqmPathSource) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) SqmSortSpecification(org.hibernate.query.sqm.tree.select.SqmSortSpecification) SqmCaseSearched(org.hibernate.query.sqm.tree.expression.SqmCaseSearched) SqmIndexedCollectionAccessPath(org.hibernate.query.sqm.tree.domain.SqmIndexedCollectionAccessPath) SqmLiteralNull(org.hibernate.query.sqm.tree.expression.SqmLiteralNull) Locale(java.util.Locale) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) SqmMapEntryReference(org.hibernate.query.sqm.tree.domain.SqmMapEntryReference) BetweenPredicate(org.hibernate.sql.ast.tree.predicate.BetweenPredicate) AbstractJdbcParameter(org.hibernate.sql.exec.internal.AbstractJdbcParameter) JdbcParameterImpl(org.hibernate.sql.exec.internal.JdbcParameterImpl) SqmOverflow(org.hibernate.query.sqm.tree.expression.SqmOverflow) ComparisonOperator(org.hibernate.query.sqm.ComparisonOperator) SqmInsertSelectStatement(org.hibernate.query.sqm.tree.insert.SqmInsertSelectStatement) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) Assignable(org.hibernate.sql.ast.tree.update.Assignable) SqmPredicate(org.hibernate.query.sqm.tree.predicate.SqmPredicate) Any(org.hibernate.sql.ast.tree.expression.Any) Assignment(org.hibernate.sql.ast.tree.update.Assignment) SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) Collection(java.util.Collection) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) OrderByFragment(org.hibernate.metamodel.mapping.ordering.OrderByFragment) SqmBinaryArithmetic(org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic) SqmJpaCriteriaParameterWrapper(org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper) SqmAnyValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmAnyValuedSimplePath) UpdateStatement(org.hibernate.sql.ast.tree.update.UpdateStatement) 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) 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) ExistsPredicate(org.hibernate.sql.ast.tree.predicate.ExistsPredicate) 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) SqmAliasedNode(org.hibernate.query.sqm.tree.select.SqmAliasedNode) SqmDynamicInstantiationArgument(org.hibernate.query.sqm.tree.select.SqmDynamicInstantiationArgument) SqmSelectableNode(org.hibernate.query.sqm.tree.select.SqmSelectableNode) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) NATIVE(org.hibernate.query.sqm.TemporalUnit.NATIVE) Logger(org.jboss.logging.Logger) UnaryOperation(org.hibernate.sql.ast.tree.expression.UnaryOperation) OptimizableGenerator(org.hibernate.id.OptimizableGenerator) SqmParameterizedEntityType(org.hibernate.query.sqm.tree.expression.SqmParameterizedEntityType) Function(java.util.function.Function) SortOrder(org.hibernate.query.sqm.SortOrder) Duration(org.hibernate.sql.ast.tree.expression.Duration) SqmEnumLiteral(org.hibernate.query.sqm.tree.expression.SqmEnumLiteral) ExtractUnit(org.hibernate.sql.ast.tree.expression.ExtractUnit) TableReference(org.hibernate.sql.ast.tree.from.TableReference) HashSet(java.util.HashSet) ModelPart(org.hibernate.metamodel.mapping.ModelPart) SqmTreatedRoot(org.hibernate.query.sqm.tree.domain.SqmTreatedRoot) SqmEvery(org.hibernate.query.sqm.tree.expression.SqmEvery) SqmNamedParameter(org.hibernate.query.sqm.tree.expression.SqmNamedParameter) SqlTreeCreationException(org.hibernate.sql.ast.SqlTreeCreationException) BinaryArithmeticOperator(org.hibernate.query.sqm.BinaryArithmeticOperator) SqmAndPredicate(org.hibernate.query.sqm.tree.predicate.SqmAndPredicate) SqlAliasBaseManager(org.hibernate.sql.ast.spi.SqlAliasBaseManager) SqmByUnit(org.hibernate.query.sqm.tree.expression.SqmByUnit) SqlAstQueryPartProcessingStateImpl(org.hibernate.query.sqm.sql.internal.SqlAstQueryPartProcessingStateImpl) CompositeNestedGeneratedValueGenerator(org.hibernate.id.CompositeNestedGeneratedValueGenerator) 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) SqmUnaryOperation(org.hibernate.query.sqm.tree.expression.SqmUnaryOperation) QueryPartTableReference(org.hibernate.sql.ast.tree.from.QueryPartTableReference) PluralPersistentAttribute(org.hibernate.metamodel.model.domain.PluralPersistentAttribute) UnaryArithmeticOperator(org.hibernate.query.sqm.UnaryArithmeticOperator) Consumer(java.util.function.Consumer) AbstractMap(java.util.AbstractMap) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) SqmInsertStatement(org.hibernate.query.sqm.tree.insert.SqmInsertStatement) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) SqlTypedMappingJdbcParameter(org.hibernate.sql.exec.internal.SqlTypedMappingJdbcParameter) SqmPluralPartJoin(org.hibernate.query.sqm.tree.domain.SqmPluralPartJoin) NonAggregatedCompositeSimplePath(org.hibernate.query.sqm.tree.domain.NonAggregatedCompositeSimplePath) BasicValueConverter(org.hibernate.metamodel.model.convert.spi.BasicValueConverter) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) 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) SqmAttributeJoin(org.hibernate.query.sqm.tree.from.SqmAttributeJoin) SqmCaseSimple(org.hibernate.query.sqm.tree.expression.SqmCaseSimple) SqlAstTreeHelper(org.hibernate.sql.ast.spi.SqlAstTreeHelper) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) 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) SqmTreatedPath(org.hibernate.query.sqm.tree.domain.SqmTreatedPath) BigDecimal(java.math.BigDecimal) SqmAliasedNodeRef(org.hibernate.query.sqm.tree.expression.SqmAliasedNodeRef) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) BindableType(org.hibernate.query.BindableType) 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) SqmCastTarget(org.hibernate.query.sqm.tree.expression.SqmCastTarget) Fetchable(org.hibernate.sql.results.graph.Fetchable) DAY(org.hibernate.query.sqm.TemporalUnit.DAY) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) ConvertedQueryLiteral(org.hibernate.sql.ast.tree.expression.ConvertedQueryLiteral) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) SqmEntityValuedSimplePath(org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath) Set(java.util.Set) Expression(org.hibernate.sql.ast.tree.expression.Expression) TemporalUnit(org.hibernate.query.sqm.TemporalUnit) SqmCollectionSize(org.hibernate.query.sqm.tree.expression.SqmCollectionSize) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) SqmTrimSpecification(org.hibernate.query.sqm.tree.expression.SqmTrimSpecification) SqlAstQueryPartProcessingState(org.hibernate.sql.ast.spi.SqlAstQueryPartProcessingState) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) JpaPath(org.hibernate.query.criteria.JpaPath) Star(org.hibernate.sql.ast.tree.expression.Star) SqmParameter(org.hibernate.query.sqm.tree.expression.SqmParameter) ValueMapping(org.hibernate.metamodel.mapping.ValueMapping) SqmPathSource(org.hibernate.query.sqm.SqmPathSource) Conversion(org.hibernate.query.sqm.tree.expression.Conversion) InsertStatement(org.hibernate.sql.ast.tree.insert.InsertStatement) SqlTypedMappingImpl(org.hibernate.metamodel.mapping.internal.SqlTypedMappingImpl) SqmJoinType(org.hibernate.query.sqm.tree.SqmJoinType) SqmCollation(org.hibernate.query.sqm.tree.expression.SqmCollation) HibernateException(org.hibernate.HibernateException) QueryException(org.hibernate.QueryException) SqmSelectClause(org.hibernate.query.sqm.tree.select.SqmSelectClause) SqmAny(org.hibernate.query.sqm.tree.expression.SqmAny) JdbcLiteral(org.hibernate.sql.ast.tree.expression.JdbcLiteral) NonAggregatedCompositeValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.NonAggregatedCompositeValuedPathInterpretation) SqmLiteralEntityType(org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType) CteContainer(org.hibernate.sql.ast.tree.cte.CteContainer) Distinct(org.hibernate.sql.ast.tree.expression.Distinct) 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) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) SqmOrPredicate(org.hibernate.query.sqm.tree.predicate.SqmOrPredicate) BiConsumer(java.util.function.BiConsumer) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding) SqmCorrelation(org.hibernate.query.sqm.tree.domain.SqmCorrelation) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) MULTIPLY(org.hibernate.query.sqm.BinaryArithmeticOperator.MULTIPLY) ReturnableType(org.hibernate.query.ReturnableType) 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) DiscriminatorSqmPath(org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath) SqmElementAggregateFunction(org.hibernate.query.sqm.tree.domain.SqmElementAggregateFunction) SqmQueryGroup(org.hibernate.query.sqm.tree.select.SqmQueryGroup) SqlTreeCreationLogger(org.hibernate.sql.ast.SqlTreeCreationLogger) StandardEntityGraphTraversalStateImpl(org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl) SqmAssignment(org.hibernate.query.sqm.tree.update.SqmAssignment) CollectionClassification(org.hibernate.metamodel.CollectionClassification) SqmWhereClause(org.hibernate.query.sqm.tree.predicate.SqmWhereClause) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) SqmGroupedPredicate(org.hibernate.query.sqm.tree.predicate.SqmGroupedPredicate) SqmPathInterpretation(org.hibernate.query.sqm.sql.internal.SqmPathInterpretation) SqmValues(org.hibernate.query.sqm.tree.insert.SqmValues) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) CollectionHelper(org.hibernate.internal.util.collections.CollectionHelper) SqmJpaCompoundSelection(org.hibernate.query.sqm.tree.select.SqmJpaCompoundSelection) ExecutionContext(org.hibernate.sql.exec.spi.ExecutionContext) CastTarget(org.hibernate.sql.ast.tree.expression.CastTarget) 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) SqmEntityJoin(org.hibernate.query.sqm.tree.from.SqmEntityJoin) SqmInListPredicate(org.hibernate.query.sqm.tree.predicate.SqmInListPredicate) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate) 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) TypeConfiguration.isDuration(org.hibernate.type.spi.TypeConfiguration.isDuration) SqmUpdateStatement(org.hibernate.query.sqm.tree.update.SqmUpdateStatement) EnumJavaType(org.hibernate.type.descriptor.java.EnumJavaType) 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) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) 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) DomainResult(org.hibernate.sql.results.graph.DomainResult) OrdinalEnumValueConverter(org.hibernate.metamodel.model.convert.internal.OrdinalEnumValueConverter) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) 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) 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) InListPredicate(org.hibernate.sql.ast.tree.predicate.InListPredicate) BasicEntityIdentifierMapping(org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping) 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) QueryLogging(org.hibernate.query.QueryLogging) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) HashMap(java.util.HashMap) SqmLiteral(org.hibernate.query.sqm.tree.expression.SqmLiteral) SqmEmptinessPredicate(org.hibernate.query.sqm.tree.predicate.SqmEmptinessPredicate) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification) AbstractSqmSpecificPluralPartPath(org.hibernate.query.sqm.tree.domain.AbstractSqmSpecificPluralPartPath) CteColumn(org.hibernate.sql.ast.tree.cte.CteColumn) SqmDynamicInstantiation(org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation) JavaObjectType(org.hibernate.type.JavaObjectType) JdbcParameters(org.hibernate.sql.exec.spi.JdbcParameters) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) LockMode(org.hibernate.LockMode) 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) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) SqmSelection(org.hibernate.query.sqm.tree.select.SqmSelection) SqmQuerySource(org.hibernate.query.sqm.SqmQuerySource) SqmCteStatement(org.hibernate.query.sqm.tree.cte.SqmCteStatement) SqmTypedNode(org.hibernate.query.sqm.tree.SqmTypedNode) EmbeddedCollectionPart(org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart) AbstractSqmSelfRenderingFunctionDescriptor(org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor) TrimSpecification(org.hibernate.sql.ast.tree.expression.TrimSpecification) 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) Every(org.hibernate.sql.ast.tree.expression.Every) SqmMappingModelHelper(org.hibernate.query.sqm.internal.SqmMappingModelHelper) QueryPart(org.hibernate.sql.ast.tree.select.QueryPart) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) Stack(org.hibernate.internal.util.collections.Stack) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) BasicValuedPathInterpretation(org.hibernate.query.sqm.sql.internal.BasicValuedPathInterpretation) Collections(java.util.Collections) EntityTypeImpl(org.hibernate.metamodel.model.domain.internal.EntityTypeImpl) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) EntityPersister(org.hibernate.persister.entity.EntityPersister) SingleTableEntityPersister(org.hibernate.persister.entity.SingleTableEntityPersister) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) SqmCorrelatedRootJoin(org.hibernate.query.sqm.tree.domain.SqmCorrelatedRootJoin) NavigablePath(org.hibernate.query.spi.NavigablePath) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) BasicEntityIdentifierMapping(org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 35 with TableGroupJoin

use of org.hibernate.sql.ast.tree.from.TableGroupJoin in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method addFetch.

public void addFetch(List<Fetch> fetches, FetchParent fetchParent, Fetchable fetchable, Boolean isKeyFetchable) {
    final NavigablePath resolvedNavigablePath = fetchParent.resolveNavigablePath(fetchable);
    final String alias;
    FetchTiming fetchTiming = fetchable.getMappedFetchOptions().getTiming();
    boolean joined = false;
    EntityGraphTraversalState.TraversalResult traversalResult = null;
    final FromClauseIndex fromClauseIndex = getFromClauseIndex();
    final SqmAttributeJoin<?, ?> fetchedJoin = fromClauseIndex.findFetchedJoinByPath(resolvedNavigablePath);
    boolean explicitFetch = false;
    final NavigablePath fetchablePath;
    if (fetchedJoin != null) {
        fetchablePath = fetchedJoin.getNavigablePath();
        // there should be a TableGroupJoin registered for this `fetchablePath` already
        assert fromClauseIndex.getTableGroup(fetchedJoin.getNavigablePath()) != null;
        if (fetchedJoin.isFetched()) {
            fetchTiming = FetchTiming.IMMEDIATE;
        }
        joined = true;
        alias = fetchedJoin.getExplicitAlias();
        explicitFetch = true;
    } else {
        fetchablePath = resolvedNavigablePath;
        // there was not an explicit fetch in the SQM
        alias = null;
        if (!(fetchable instanceof CollectionPart)) {
            if (entityGraphTraversalState != null) {
                traversalResult = entityGraphTraversalState.traverse(fetchParent, fetchable, isKeyFetchable);
                fetchTiming = traversalResult.getFetchTiming();
                joined = traversalResult.isJoined();
                explicitFetch = true;
            } else if (getLoadQueryInfluencers().hasEnabledFetchProfiles()) {
                // There is no point in checking the fetch profile if it can't affect this fetchable
                if (fetchTiming != FetchTiming.IMMEDIATE || fetchable.incrementFetchDepth()) {
                    final String fetchableRole = fetchable.getNavigableRole().getFullPath();
                    for (String enabledFetchProfileName : getLoadQueryInfluencers().getEnabledFetchProfileNames()) {
                        final FetchProfile enabledFetchProfile = getCreationContext().getSessionFactory().getFetchProfile(enabledFetchProfileName);
                        final org.hibernate.engine.profile.Fetch profileFetch = enabledFetchProfile.getFetchByRole(fetchableRole);
                        if (profileFetch != null) {
                            fetchTiming = FetchTiming.IMMEDIATE;
                            joined = joined || profileFetch.getStyle() == org.hibernate.engine.profile.Fetch.Style.JOIN;
                            explicitFetch = true;
                            if (currentBagRole != null && fetchable instanceof PluralAttributeMapping) {
                                final CollectionClassification collectionClassification = ((PluralAttributeMapping) fetchable).getMappedType().getCollectionSemantics().getCollectionClassification();
                                if (collectionClassification == CollectionClassification.BAG) {
                                    // To avoid a MultipleBagFetchException due to fetch profiles in a circular model,
                                    // we skip join fetching in case we encounter an existing bag role
                                    joined = false;
                                }
                            }
                        }
                    }
                }
            }
        }
        // final TableGroup existingJoinedGroup = fromClauseIndex.findTableGroup( fetchablePath );
        // if ( existingJoinedGroup != null ) {
        // we can use this to trigger the fetch from the joined group.
        // todo (6.0) : do we want to do this though?
        // On the positive side it would allow EntityGraph to use the existing TableGroup.  But that ties in
        // to the discussion above regarding how to handle eager and EntityGraph (JOIN versus SELECT).
        // Can be problematic if the existing one is restricted
        // fetchTiming = FetchTiming.IMMEDIATE;
        // }
        // lastly, account for any app-defined max-fetch-depth
        final Integer maxDepth = getCreationContext().getMaximumFetchDepth();
        if (maxDepth != null) {
            if (fetchDepth >= maxDepth) {
                joined = false;
            }
        }
        if (joined && fetchable instanceof TableGroupJoinProducer) {
            TableGroupJoinProducer tableGroupJoinProducer = (TableGroupJoinProducer) fetchable;
            fromClauseIndex.resolveTableGroup(fetchablePath, np -> {
                // generate the join
                final TableGroup lhs = fromClauseIndex.getTableGroup(fetchParent.getNavigablePath());
                final TableGroupJoin tableGroupJoin = ((TableGroupJoinProducer) fetchable).createTableGroupJoin(fetchablePath, lhs, alias, tableGroupJoinProducer.getDefaultSqlAstJoinType(lhs), true, false, BaseSqmToSqlAstConverter.this);
                lhs.addTableGroupJoin(tableGroupJoin);
                return tableGroupJoin.getJoinedGroup();
            });
        }
    }
    final boolean incrementFetchDepth = fetchable.incrementFetchDepth();
    try {
        if (incrementFetchDepth) {
            fetchDepth++;
        }
        // There is no need to check for circular fetches if this is an explicit fetch
        if (!explicitFetch && !isResolvingCircularFetch()) {
            final Fetch biDirectionalFetch = fetchable.resolveCircularFetch(fetchablePath, fetchParent, fetchTiming, this);
            if (biDirectionalFetch != null) {
                fetches.add(biDirectionalFetch);
                return;
            }
        }
        final Fetch fetch = buildFetch(fetchablePath, fetchParent, fetchable, fetchTiming, joined, alias);
        if (fetch != null) {
            if (fetch.getTiming() == FetchTiming.IMMEDIATE && fetchable instanceof PluralAttributeMapping) {
                final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
                final CollectionClassification collectionClassification = pluralAttributeMapping.getMappedType().getCollectionSemantics().getCollectionClassification();
                if (collectionClassification == CollectionClassification.BAG) {
                    if (currentBagRole != null) {
                        throw new MultipleBagFetchException(Arrays.asList(currentBagRole, fetchable.getNavigableRole().getNavigableName()));
                    }
                    currentBagRole = fetchable.getNavigableRole().getNavigableName();
                }
            }
            fetches.add(fetch);
        }
    } finally {
        if (incrementFetchDepth) {
            fetchDepth--;
        }
        if (entityGraphTraversalState != null && traversalResult != null) {
            entityGraphTraversalState.backtrack(traversalResult);
        }
    }
}
Also used : EntityGraphTraversalState(org.hibernate.sql.results.graph.EntityGraphTraversalState) FetchProfile(org.hibernate.engine.profile.FetchProfile) NavigablePath(org.hibernate.query.spi.NavigablePath) TableGroupJoinProducer(org.hibernate.sql.ast.tree.from.TableGroupJoinProducer) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) Fetch(org.hibernate.sql.results.graph.Fetch) BigInteger(java.math.BigInteger) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) CollectionClassification(org.hibernate.metamodel.CollectionClassification) FetchTiming(org.hibernate.engine.FetchTiming) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) EmbeddedCollectionPart(org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart) MultipleBagFetchException(org.hibernate.loader.MultipleBagFetchException)

Aggregations

TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)39 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)34 LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)17 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)14 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)14 NavigablePath (org.hibernate.query.spi.NavigablePath)13 SqlAstJoinType (org.hibernate.sql.ast.SqlAstJoinType)13 EntityPersister (org.hibernate.persister.entity.EntityPersister)11 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)11 QueryPartTableGroup (org.hibernate.sql.ast.tree.from.QueryPartTableGroup)10 TableGroupJoinProducer (org.hibernate.sql.ast.tree.from.TableGroupJoinProducer)10 VirtualTableGroup (org.hibernate.sql.ast.tree.from.VirtualTableGroup)10 Fetch (org.hibernate.sql.results.graph.Fetch)10 CorrelatedPluralTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup)9 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)9 EntityValuedModelPart (org.hibernate.metamodel.mapping.EntityValuedModelPart)8 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)8 DomainResult (org.hibernate.sql.results.graph.DomainResult)8 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)7 ModelPart (org.hibernate.metamodel.mapping.ModelPart)7