diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index ad8eb2ac32..8fc5094f56 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -760,11 +760,6 @@ public abstract class BaseSqmToSqlAstConverter extends Base return currentSqmQueryPart; } - @Override - public SqmStatement getCurrentSqmStatement() { - return currentSqmStatement; - } - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Statements diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java index 9e69d45ef0..118e66226b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/FakeSqmToSqlAstConverter.java @@ -14,7 +14,6 @@ import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.internal.util.collections.Stack; import org.hibernate.metamodel.mapping.MappingModelExpressible; import org.hibernate.query.sqm.spi.BaseSemanticQueryWalker; -import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.SqmVisitableNode; import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.expression.SqmParameter; @@ -93,11 +92,6 @@ public class FakeSqmToSqlAstConverter extends BaseSemanticQueryWalker implements return null; } - @Override - public SqmStatement getCurrentSqmStatement() { - return null; - } - @Override public void registerQueryTransformer(QueryTransformer transformer) { } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/SqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/SqmToSqlAstConverter.java index d90962db08..378fef24be 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/SqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/SqmToSqlAstConverter.java @@ -12,7 +12,6 @@ import java.util.function.Supplier; import org.hibernate.internal.util.collections.Stack; import org.hibernate.metamodel.mapping.MappingModelExpressible; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.SqmVisitableNode; import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.expression.SqmParameter; @@ -34,8 +33,6 @@ public interface SqmToSqlAstConverter extends SemanticQueryWalker, SqlAs SqmQueryPart getCurrentSqmQueryPart(); - SqmStatement getCurrentSqmStatement(); - void registerQueryTransformer(QueryTransformer transformer); /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java index b4bdeba3a2..7dddcde85f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java @@ -6,29 +6,19 @@ */ package org.hibernate.query.sqm.sql.internal; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; - import org.hibernate.metamodel.MappingMetamodel; -import org.hibernate.metamodel.mapping.BasicValuedModelPart; -import org.hibernate.metamodel.mapping.EntityMappingType; -import org.hibernate.metamodel.mapping.ManagedMappingType; -import org.hibernate.metamodel.mapping.MappingType; -import org.hibernate.metamodel.mapping.ModelPart; -import org.hibernate.metamodel.mapping.ModelPartContainer; +import org.hibernate.metamodel.mapping.*; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; -import org.hibernate.query.sqm.tree.SqmStatement; -import org.hibernate.query.sqm.tree.from.SqmFrom; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.sqm.tree.domain.SqmPath; -import org.hibernate.query.sqm.tree.select.SqmSelectStatement; -import org.hibernate.spi.NavigablePath; import org.hibernate.query.SemanticException; import org.hibernate.query.sqm.StrictJpaComplianceViolation; +import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath; +import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; +import org.hibernate.query.sqm.tree.from.SqmFrom; +import org.hibernate.query.sqm.tree.select.SqmQueryPart; +import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.spi.FromClauseAccess; @@ -39,6 +29,10 @@ import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.update.Assignable; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + /** * @author Steve Ebersole */ @@ -91,12 +85,12 @@ public class BasicValuedPathInterpretation extends AbstractSqmPathInterpretat // never the FK column, if the lhs is a SqmFrom i.e. something explicitly queried/joined // and if this basic path is part of the group by clause final Clause currentClause = sqlAstCreationState.getCurrentClauseStack().getCurrent(); - final SqmStatement sqmStatement = sqlAstCreationState.getCurrentSqmStatement(); + final SqmQueryPart sqmQueryPart = sqlAstCreationState.getCurrentSqmQueryPart(); if ( ( currentClause == Clause.GROUP || currentClause == Clause.SELECT || currentClause == Clause.ORDER || currentClause == Clause.HAVING ) && sqmPath.getLhs() instanceof SqmFrom && modelPartContainer.getPartMappingType() instanceof ManagedMappingType - && sqmStatement instanceof SqmSelectStatement - && ( (SqmSelectStatement) sqmStatement ).getQuerySpec().groupByClauseContains( sqmPath.getNavigablePath() ) ) { + && sqmQueryPart.isSimpleQueryPart() + && sqmQueryPart.getFirstQuerySpec().groupByClauseContains( sqmPath.getNavigablePath() ) ) { mapping = (BasicValuedModelPart) ( (ManagedMappingType) modelPartContainer.getPartMappingType() ).findSubPart( sqmPath.getReferencedPathSource().getPathName(), treatTarget diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java index 256e2f6a05..e756bc22b9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java @@ -16,13 +16,12 @@ import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.query.sqm.tree.SqmStatement; -import org.hibernate.query.sqm.tree.from.SqmFrom; -import org.hibernate.query.sqm.tree.select.SqmSelectStatement; -import org.hibernate.spi.NavigablePath; import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; import org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; +import org.hibernate.query.sqm.tree.from.SqmFrom; +import org.hibernate.query.sqm.tree.select.SqmQueryPart; +import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.tree.expression.ColumnReference; @@ -71,12 +70,12 @@ public class EmbeddableValuedPathInterpretation extends AbstractSqmPathInterp // never the FK column, if the lhs is a SqmFrom i.e. something explicitly queried/joined // and if this basic path is part of the group by clause final Clause currentClause = sqlAstCreationState.getCurrentClauseStack().getCurrent(); - final SqmStatement sqmStatement = sqlAstCreationState.getCurrentSqmStatement(); + final SqmQueryPart sqmQueryPart = sqlAstCreationState.getCurrentSqmQueryPart(); if ( ( currentClause == Clause.GROUP || currentClause == Clause.SELECT || currentClause == Clause.ORDER || currentClause == Clause.HAVING ) && sqmPath.getLhs() instanceof SqmFrom && modelPart.getPartMappingType() instanceof ManagedMappingType - && sqmStatement instanceof SqmSelectStatement - && ( (SqmSelectStatement) sqmStatement ).getQuerySpec().groupByClauseContains( sqmPath.getNavigablePath() ) ) { + && sqmQueryPart.isSimpleQueryPart() + && sqmQueryPart.getFirstQuerySpec().groupByClauseContains( sqmPath.getNavigablePath() ) ) { mapping = (EmbeddableValuedModelPart) ( (ManagedMappingType) modelPart.getPartMappingType() ).findSubPart( sqmPath.getReferencedPathSource().getPathName(), treatTarget