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 b16705fdb8..15d5ffbdb2 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 @@ -2822,27 +2822,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base private void registerSqmFromTableGroup(SqmFrom sqmFrom, TableGroup tableGroup) { getFromClauseIndex().register( sqmFrom, tableGroup ); // We also need to register the table group for the treats - if ( tableGroup instanceof PluralTableGroup ) { - final PluralTableGroup pluralTableGroup = (PluralTableGroup) tableGroup; - for ( SqmFrom sqmTreat : sqmFrom.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 : sqmFrom.getSqmTreats() ) { - getFromClauseAccess().registerTableGroup( sqmTreat.getNavigablePath(), tableGroup ); - } + for ( SqmFrom sqmTreat : sqmFrom.getSqmTreats() ) { + getFromClauseAccess().registerTableGroup( sqmTreat.getNavigablePath(), tableGroup ); } } 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 47df7c1795..917a5ef78d 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 @@ -27,11 +27,9 @@ 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.query.sqm.tree.select.SqmQuerySpec; import org.hibernate.spi.NavigablePath; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.SqlAstWalker; -import org.hibernate.sql.ast.spi.FromClauseAccess; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.SqlSelectionExpression; 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 e756bc22b9..69a6ac302b 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 @@ -18,6 +18,7 @@ import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; import org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath; +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; @@ -43,22 +44,22 @@ public class EmbeddableValuedPathInterpretation extends AbstractSqmPathInterp SqmEmbeddedValuedSimplePath sqmPath, SqmToSqlAstConverter sqlAstCreationState, boolean jpaQueryComplianceEnabled) { - TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().findTableGroup( sqmPath.getLhs().getNavigablePath() ); - + final SqmPath lhs = sqmPath.getLhs(); + final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().getTableGroup( lhs.getNavigablePath() ); EntityMappingType treatTarget = null; if ( jpaQueryComplianceEnabled ) { final MappingMetamodel mappingMetamodel = sqlAstCreationState.getCreationContext() .getSessionFactory() .getRuntimeMetamodels() .getMappingMetamodel(); - if ( sqmPath.getLhs() instanceof SqmTreatedPath ) { + if ( lhs instanceof SqmTreatedPath ) { //noinspection rawtypes - final EntityDomainType treatTargetDomainType = ( (SqmTreatedPath) sqmPath.getLhs() ).getTreatTarget(); + final EntityDomainType treatTargetDomainType = ( (SqmTreatedPath) lhs ).getTreatTarget(); treatTarget = mappingMetamodel.findEntityDescriptor( treatTargetDomainType.getHibernateEntityName() ); } - else if ( sqmPath.getLhs().getNodeType() instanceof EntityDomainType ) { + else if ( lhs.getNodeType() instanceof EntityDomainType ) { //noinspection rawtypes - final EntityDomainType entityDomainType = (EntityDomainType) sqmPath.getLhs().getNodeType(); + final EntityDomainType entityDomainType = (EntityDomainType) lhs.getNodeType(); treatTarget = mappingMetamodel.findEntityDescriptor( entityDomainType.getHibernateEntityName() ); } @@ -72,7 +73,7 @@ public class EmbeddableValuedPathInterpretation extends AbstractSqmPathInterp final Clause currentClause = sqlAstCreationState.getCurrentClauseStack().getCurrent(); final SqmQueryPart sqmQueryPart = sqlAstCreationState.getCurrentSqmQueryPart(); if ( ( currentClause == Clause.GROUP || currentClause == Clause.SELECT || currentClause == Clause.ORDER || currentClause == Clause.HAVING ) - && sqmPath.getLhs() instanceof SqmFrom + && lhs instanceof SqmFrom && modelPart.getPartMappingType() instanceof ManagedMappingType && sqmQueryPart.isSimpleQueryPart() && sqmQueryPart.getFirstQuerySpec().groupByClauseContains( sqmPath.getNavigablePath() ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedBagJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedBagJoin.java index 6e6b689478..a4a3aedc49 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedBagJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedBagJoin.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.sqm.tree.domain; +import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.model.domain.BagPersistentAttribute; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.query.hql.spi.SqmCreationProcessingState; @@ -28,10 +29,9 @@ public class SqmTreatedBagJoin extends SqmBagJoin impleme //noinspection unchecked super( wrappedPath.getLhs(), - wrappedPath.getNavigablePath().treatAs( - treatTarget.getHibernateEntityName(), - alias - ), + wrappedPath.getNavigablePath() + .append( CollectionPart.Nature.ELEMENT.getName() ) + .treatAs( treatTarget.getHibernateEntityName(), alias ), (BagPersistentAttribute) wrappedPath.getAttribute(), alias, wrappedPath.getSqmJoinType(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedListJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedListJoin.java index 56706414de..c24f0f76e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedListJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedListJoin.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.sqm.tree.domain; +import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.ListPersistentAttribute; import org.hibernate.query.hql.spi.SqmCreationProcessingState; @@ -30,10 +31,9 @@ public class SqmTreatedListJoin extends SqmListJoin imple //noinspection unchecked super( wrappedPath.getLhs(), - wrappedPath.getNavigablePath().treatAs( - treatTarget.getHibernateEntityName(), - alias - ), + wrappedPath.getNavigablePath() + .append( CollectionPart.Nature.ELEMENT.getName() ) + .treatAs( treatTarget.getHibernateEntityName(), alias ), (ListPersistentAttribute) wrappedPath.getAttribute(), alias, wrappedPath.getSqmJoinType(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java index dbf435a627..c89cc28122 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedMapJoin.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.sqm.tree.domain; +import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.query.hql.spi.SqmCreationProcessingState; import org.hibernate.query.sqm.SqmPathSource; @@ -26,10 +27,9 @@ public class SqmTreatedMapJoin extends SqmMapJoin //noinspection unchecked super( wrappedPath.getLhs(), - wrappedPath.getNavigablePath().treatAs( - treatTarget.getHibernateEntityName(), - alias - ), + wrappedPath.getNavigablePath() + .append( CollectionPart.Nature.ELEMENT.getName() ) + .treatAs( treatTarget.getHibernateEntityName(), alias ), ( (SqmMapJoin) wrappedPath ).getModel(), alias, wrappedPath.getSqmJoinType(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSetJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSetJoin.java index 218363119c..76388897ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSetJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSetJoin.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.sqm.tree.domain; +import org.hibernate.metamodel.mapping.CollectionPart; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.SetPersistentAttribute; import org.hibernate.query.hql.spi.SqmCreationProcessingState; @@ -28,10 +29,9 @@ public class SqmTreatedSetJoin extends SqmSetJoin impleme //noinspection unchecked super( wrappedPath.getLhs(), - wrappedPath.getNavigablePath().treatAs( - treatTarget.getHibernateEntityName(), - alias - ), + wrappedPath.getNavigablePath() + .append( CollectionPart.Nature.ELEMENT.getName() ) + .treatAs( treatTarget.getHibernateEntityName(), alias ), (SetPersistentAttribute) wrappedPath.getAttribute(), alias, wrappedPath.getSqmJoinType(),