From e4dae1b31997687addc3335f3d682e1ba0317e2d Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Mon, 22 May 2023 10:25:25 +0200 Subject: [PATCH] HHH-16574 Return treat type as path source for treated joins --- .../internal/QualifiedJoinPathConsumer.java | 9 ++- .../query/hql/internal/QuerySplitter.java | 10 +-- .../sqm/sql/BaseSqmToSqlAstConverter.java | 72 ++++++++++--------- .../sqm/tree/domain/AbstractSqmPath.java | 4 +- .../tree/domain/AbstractSqmPluralJoin.java | 7 +- .../query/sqm/tree/domain/SqmBagJoin.java | 15 ++-- .../sqm/tree/domain/SqmCorrelatedBagJoin.java | 4 +- .../tree/domain/SqmCorrelatedListJoin.java | 4 +- .../sqm/tree/domain/SqmCorrelatedMapJoin.java | 4 +- .../sqm/tree/domain/SqmCorrelatedSetJoin.java | 4 +- .../domain/SqmCorrelatedSingularJoin.java | 4 +- .../query/sqm/tree/domain/SqmListJoin.java | 16 ++--- .../query/sqm/tree/domain/SqmMapJoin.java | 17 ++--- .../query/sqm/tree/domain/SqmSetJoin.java | 17 ++--- .../sqm/tree/domain/SqmSingularJoin.java | 15 ++-- .../sqm/tree/domain/SqmTreatedBagJoin.java | 5 ++ .../sqm/tree/domain/SqmTreatedEntityJoin.java | 3 +- .../sqm/tree/domain/SqmTreatedListJoin.java | 10 +-- .../sqm/tree/domain/SqmTreatedMapJoin.java | 5 ++ .../sqm/tree/domain/SqmTreatedSetJoin.java | 9 +-- .../tree/domain/SqmTreatedSingularJoin.java | 5 ++ 21 files changed, 112 insertions(+), 127 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java index 9425b2de7c..53fe409e40 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java @@ -178,8 +178,15 @@ public class QualifiedJoinPathConsumer implements DotIdentifierConsumer { boolean isTerminal, boolean allowReuse, SqmCreationState creationState) { + final SqmPathSource referencedPathSource = lhs.getReferencedPathSource(); + // We need to use referencedPathSource when it is not generic since the getResolvedModel() method would + // return the association attribute as a path source and for treated paths that might correspond to a + // different entity type (usually the first in alphabetical order) and not the correct treat target + final SqmPathSource pathSource = referencedPathSource.isGeneric() ? + lhs.getResolvedModel() : + referencedPathSource; //noinspection unchecked - final SqmPathSource subPathSource = (SqmPathSource) lhs.getReferencedPathSource().getSubPathSource( name ); + final SqmPathSource subPathSource = (SqmPathSource) pathSource.getSubPathSource( name ); if ( allowReuse && !isTerminal ) { for ( SqmJoin sqmJoin : lhs.getSqmJoins() ) { if ( sqmJoin.getAlias() == null && sqmJoin.getReferencedPathSource() == subPathSource ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java index 83d1f64eee..ecb73c0606 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java @@ -746,7 +746,7 @@ public class QuerySplitter { final SqmBagJoin copy = new SqmBagJoin<>( findSqmFromCopy( join.getLhs() ), - join.getReferencedPathSource(), + join.getAttribute(), join.getExplicitAlias(), join.getSqmJoinType(), join.isFetched(), @@ -846,7 +846,7 @@ public class QuerySplitter { final SqmListJoin copy = new SqmListJoin<>( findSqmFromCopy( join.getLhs() ), - join.getReferencedPathSource(), + join.getAttribute(), join.getExplicitAlias(), join.getSqmJoinType(), join.isFetched(), @@ -867,7 +867,7 @@ public class QuerySplitter { final SqmMapJoin copy = new SqmMapJoin<>( findSqmFromCopy( join.getLhs() ), - join.getReferencedPathSource(), + join.getAttribute(), join.getExplicitAlias(), join.getSqmJoinType(), join.isFetched(), @@ -888,7 +888,7 @@ public class QuerySplitter { final SqmSetJoin copy = new SqmSetJoin<>( findSqmFromCopy( join.getLhs() ), - join.getReferencedPathSource(), + join.getAttribute(), join.getExplicitAlias(), join.getSqmJoinType(), join.isFetched(), @@ -909,7 +909,7 @@ public class QuerySplitter { final SqmSingularJoin copy = new SqmSingularJoin<>( findSqmFromCopy( join.getLhs() ), - join.getReferencedPathSource(), + join.getAttribute(), join.getExplicitAlias(), join.getSqmJoinType(), join.isFetched(), 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 728dd1badc..d19bc5afdd 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 @@ -2796,12 +2796,39 @@ public abstract class BaseSqmToSqlAstConverter extends Base log.tracef( "Resolved SqmRoot [%s] to new TableGroup [%s]", sqmRoot, tableGroup ); - fromClauseIndex.register( sqmRoot, tableGroup ); + registerSqmFromTableGroup( sqmRoot, tableGroup ); currentQuerySpec.getFromClause().addRoot( tableGroup ); consumeJoins( sqmRoot, fromClauseIndex, tableGroup ); } + 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 ); + } + } + } + private TableGroup createCteTableGroup( String cteName, NavigablePath navigablePath, @@ -3290,34 +3317,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base lhsTableGroup.addTableGroupJoin( joinedTableGroupJoin ); - getFromClauseIndex().register( sqmJoin, joinedTableGroup ); + registerSqmFromTableGroup( 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 - ); - } - } if ( sqmJoin.isFetched() ) { // A fetch is like a projection usage, so register that properly registerEntityNameProjectionUsage( sqmJoin, getActualTableGroup( joinedTableGroup, sqmJoin ) ); @@ -3372,7 +3373,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base lhsTableGroup.addTableGroupJoin( tableGroupJoin ); - getFromClauseIndex().register( sqmJoin, tableGroup ); + registerSqmFromTableGroup( sqmJoin, tableGroup ); if ( transitive ) { consumeExplicitJoins( sqmJoin, tableGroupJoin.getJoinedGroup() ); @@ -3392,8 +3393,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base null, () -> p -> predicate.set( combinePredicates( predicate.get(), p ) ), this - ); - getFromClauseIndex().register( sqmJoin, tableGroup ); + ); + registerSqmFromTableGroup( sqmJoin, tableGroup ); final TableGroupJoin tableGroupJoin = new TableGroupJoin( sqmJoin.getNavigablePath(), @@ -5148,9 +5149,12 @@ public abstract class BaseSqmToSqlAstConverter extends Base } private Predicate createTreatTypeRestriction(SqmPath lhs, EntityDomainType treatTarget) { - final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( treatTarget.getHibernateEntityName() ); - final Set subclassEntityNames = entityDescriptor.getSubclassEntityNames(); - return createTreatTypeRestriction( lhs, subclassEntityNames ); + final AbstractEntityPersister entityDescriptor = (AbstractEntityPersister) domainModel.findEntityDescriptor( treatTarget.getHibernateEntityName() ); + if ( entityDescriptor.isPolymorphic() ) { + final Set subclassEntityNames = entityDescriptor.getSubclassEntityNames(); + return createTreatTypeRestriction( lhs, subclassEntityNames ); + } + return null; } private Predicate createTreatTypeRestriction(SqmPath lhs, Set subclassEntityNames) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java index 48f09f058c..ab4dc5bb43 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java @@ -188,7 +188,7 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem protected SqmPath resolvePath(String attributeName, SqmPathSource pathSource) { if ( reusablePaths == null ) { reusablePaths = new HashMap<>(); - final SqmPath path = pathSource.createSqmPath( this, getReferencedPathSource().getIntermediatePathSource( pathSource ) ); + final SqmPath path = pathSource.createSqmPath( this, getResolvedModel().getIntermediatePathSource( pathSource ) ); reusablePaths.put( attributeName, path ); return path; } @@ -196,7 +196,7 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem //noinspection unchecked return (SqmPath) reusablePaths.computeIfAbsent( attributeName, - name -> pathSource.createSqmPath( this, getReferencedPathSource().getIntermediatePathSource( pathSource ) ) + name -> pathSource.createSqmPath( this, getResolvedModel().getIntermediatePathSource( pathSource ) ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPluralJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPluralJoin.java index 18a26e9c21..e701c43706 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPluralJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPluralJoin.java @@ -41,13 +41,8 @@ public abstract class AbstractSqmPluralJoin extends AbstractSqmAttributeJ super( lhs, navigablePath, joinedNavigable, alias, joinType, fetched, nodeBuilder ); } - @Override - public PluralPersistentAttribute getReferencedPathSource() { - return (PluralPersistentAttribute) super.getReferencedPathSource(); - } - @Override public PluralPersistentAttribute getModel() { - return getReferencedPathSource(); + return (PluralPersistentAttribute) super.getNodeType(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBagJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBagJoin.java index 8e15b1586a..6a569938d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBagJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBagJoin.java @@ -61,7 +61,7 @@ public class SqmBagJoin extends AbstractSqmPluralJoin, E> new SqmBagJoin<>( getLhs().copy( context ), getNavigablePath(), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -72,14 +72,9 @@ public class SqmBagJoin extends AbstractSqmPluralJoin, E> return path; } - @Override - public BagPersistentAttribute getReferencedPathSource() { - return (BagPersistentAttribute) super.getReferencedPathSource(); - } - @Override public BagPersistentAttribute getModel() { - return getReferencedPathSource(); + return (BagPersistentAttribute) super.getModel(); } @Override @@ -89,8 +84,7 @@ public class SqmBagJoin extends AbstractSqmPluralJoin, E> @Override public BagPersistentAttribute getAttribute() { - //noinspection unchecked - return (BagPersistentAttribute) super.getAttribute(); + return getModel(); } @Override @@ -148,12 +142,11 @@ public class SqmBagJoin extends AbstractSqmPluralJoin, E> public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmBagJoin<>( creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), nodeBuilder() ); } - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java index 1be4b7cee8..e2149ebce8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedBagJoin.java @@ -62,7 +62,7 @@ public class SqmCorrelatedBagJoin extends SqmBagJoin implements SqmC this, new SqmCorrelatedBagJoin<>( getLhs().copy( context ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -105,7 +105,7 @@ public class SqmCorrelatedBagJoin extends SqmBagJoin implements SqmC final SqmPathRegistry pathRegistry = creationProcessingState.getPathRegistry(); return new SqmCorrelatedBagJoin<>( pathRegistry.findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java index 99b815a2bf..7e52197da1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedListJoin.java @@ -62,7 +62,7 @@ public class SqmCorrelatedListJoin extends SqmListJoin implements Sq this, new SqmCorrelatedListJoin<>( getLhs().copy( context ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -100,7 +100,7 @@ public class SqmCorrelatedListJoin extends SqmListJoin implements Sq final SqmPathRegistry pathRegistry = creationProcessingState.getPathRegistry(); return new SqmCorrelatedListJoin<>( pathRegistry.findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java index 4f0f124713..d984bbeb88 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedMapJoin.java @@ -62,7 +62,7 @@ public class SqmCorrelatedMapJoin extends SqmMapJoin implement this, new SqmCorrelatedMapJoin<>( getLhs().copy( context ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -100,7 +100,7 @@ public class SqmCorrelatedMapJoin extends SqmMapJoin implement final SqmPathRegistry pathRegistry = creationProcessingState.getPathRegistry(); return new SqmCorrelatedMapJoin<>( pathRegistry.findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java index d9381bcfd8..b6e4bd8ed7 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSetJoin.java @@ -62,7 +62,7 @@ public class SqmCorrelatedSetJoin extends SqmSetJoin implements SqmC this, new SqmCorrelatedSetJoin<>( getLhs().copy( context ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -100,7 +100,7 @@ public class SqmCorrelatedSetJoin extends SqmSetJoin implements SqmC final SqmPathRegistry pathRegistry = creationProcessingState.getPathRegistry(); return new SqmCorrelatedSetJoin<>( pathRegistry.findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java index 85283485a6..030df61389 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmCorrelatedSingularJoin.java @@ -62,7 +62,7 @@ public class SqmCorrelatedSingularJoin extends SqmSingularJoin imple this, new SqmCorrelatedSingularJoin<>( getLhs().copy( context ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -100,7 +100,7 @@ public class SqmCorrelatedSingularJoin extends SqmSingularJoin imple final SqmPathRegistry pathRegistry = creationProcessingState.getPathRegistry(); return new SqmCorrelatedSingularJoin<>( pathRegistry.findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmListJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmListJoin.java index 8bceb53f87..e0b52a7331 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmListJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmListJoin.java @@ -64,7 +64,7 @@ public class SqmListJoin new SqmListJoin<>( getLhs().copy( context ), getNavigablePath(), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -75,14 +75,9 @@ public class SqmListJoin return path; } - @Override - public ListPersistentAttribute getReferencedPathSource() { - return (ListPersistentAttribute) super.getReferencedPathSource(); - } - @Override public ListPersistentAttribute getModel() { - return getReferencedPathSource(); + return (ListPersistentAttribute) super.getModel(); } @Override @@ -92,13 +87,12 @@ public class SqmListJoin @Override public ListPersistentAttribute getAttribute() { - //noinspection unchecked - return (ListPersistentAttribute) super.getAttribute(); + return getModel(); } @Override public SqmPath index() { - final SqmPathSource indexPathSource = getReferencedPathSource().getIndexPathSource(); + final SqmPathSource indexPathSource = getAttribute().getIndexPathSource(); return resolvePath( indexPathSource.getPathName(), indexPathSource ); } @@ -155,7 +149,7 @@ public class SqmListJoin public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmListJoin<>( creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java index 22f1ed6acc..ad7d001857 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapJoin.java @@ -63,7 +63,7 @@ public class SqmMapJoin new SqmMapJoin<>( getLhs().copy( context ), getNavigablePath(), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -74,11 +74,6 @@ public class SqmMapJoin return path; } - @Override - public MapPersistentAttribute getReferencedPathSource() { - return(MapPersistentAttribute) super.getReferencedPathSource(); - } - @Override public MapPersistentAttribute getModel() { return (MapPersistentAttribute) super.getModel(); @@ -91,23 +86,21 @@ public class SqmMapJoin @Override public MapPersistentAttribute getAttribute() { - //noinspection unchecked - return (MapPersistentAttribute) super.getAttribute(); + return getModel(); } - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // JPA @Override public SqmPath key() { - final SqmPathSource keyPathSource = getReferencedPathSource().getKeyPathSource(); + final SqmPathSource keyPathSource = getAttribute().getKeyPathSource(); return resolvePath( keyPathSource.getPathName(), keyPathSource ); } @Override public Path value() { - final SqmPathSource elementPathSource = getReferencedPathSource().getElementPathSource(); + final SqmPathSource elementPathSource = getAttribute().getElementPathSource(); return resolvePath( elementPathSource.getPathName(), elementPathSource ); } @@ -169,7 +162,7 @@ public class SqmMapJoin public SqmMapJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmMapJoin<>( creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java index 14b795e69f..ab7fac1d5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSetJoin.java @@ -63,7 +63,7 @@ public class SqmSetJoin new SqmSetJoin<>( getLhs().copy( context ), getNavigablePath(), - getReferencedPathSource(), + getModel(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -75,13 +75,8 @@ public class SqmSetJoin } @Override - public SetPersistentAttribute getReferencedPathSource() { - return (SetPersistentAttribute) super.getReferencedPathSource(); - } - - @Override - public SetPersistentAttribute getModel() { - return getReferencedPathSource(); + public SetPersistentAttribute getModel() { + return (SetPersistentAttribute) super.getNodeType(); } @Override @@ -90,8 +85,8 @@ public class SqmSetJoin } @Override - public SetPersistentAttribute getAttribute() { - return getReferencedPathSource(); + public SetPersistentAttribute getAttribute() { + return getModel(); } @Override @@ -153,7 +148,7 @@ public class SqmSetJoin public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmSetJoin<>( creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getModel(), getExplicitAlias(), getSqmJoinType(), isFetched(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java index e26828fb9d..f7dfdf134a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java @@ -11,6 +11,7 @@ import java.util.Locale; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.spi.NavigablePath; import org.hibernate.query.hql.spi.SqmCreationProcessingState; import org.hibernate.query.sqm.NodeBuilder; @@ -71,7 +72,7 @@ public class SqmSingularJoin extends AbstractSqmAttributeJoin { new SqmSingularJoin<>( getLhs().copy( context ), getNavigablePath(), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), @@ -82,20 +83,14 @@ public class SqmSingularJoin extends AbstractSqmAttributeJoin { return path; } - @Override - public SingularPersistentAttribute getReferencedPathSource() { - return (SingularPersistentAttribute) super.getReferencedPathSource(); - } - @Override public SingularPersistentAttribute getModel() { - return getReferencedPathSource(); + return (SingularPersistentAttribute) super.getNodeType(); } @Override public SingularPersistentAttribute getAttribute() { - //noinspection unchecked - return (SingularPersistentAttribute) super.getAttribute(); + return getModel(); } @Override @@ -141,7 +136,7 @@ public class SqmSingularJoin extends AbstractSqmAttributeJoin { public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmSingularJoin<>( creationProcessingState.getPathRegistry().findFromByPath( getLhs().getNavigablePath() ), - getReferencedPathSource(), + getAttribute(), getExplicitAlias(), getSqmJoinType(), isFetched(), 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 ae16d1d5e0..1f6127a4b1 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 @@ -75,6 +75,11 @@ public class SqmTreatedBagJoin extends SqmBagJoin impleme return treatTarget; } + @Override + public EntityDomainType getReferencedPathSource() { + return treatTarget; + } + @Override public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmTreatedBagJoin<>( wrappedPath, treatTarget, getAlias() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEntityJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEntityJoin.java index 827e7de7f0..f8c5710c65 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEntityJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedEntityJoin.java @@ -72,8 +72,7 @@ public class SqmTreatedEntityJoin extends SqmEntityJoin imple @Override public EntityDomainType getReferencedPathSource() { - //noinspection unchecked - return (EntityDomainType) wrappedPath.getReferencedPathSource(); + return treatTarget; } @Override 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 1dd44d6241..74c49ddbb7 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 @@ -67,11 +67,6 @@ public class SqmTreatedListJoin extends SqmListJoin imple return wrappedPath; } - @Override - public ListPersistentAttribute getModel() { - return super.getModel(); - } - @Override public EntityDomainType getTreatTarget() { return treatTarget; @@ -82,6 +77,11 @@ public class SqmTreatedListJoin extends SqmListJoin imple return treatTarget; } + @Override + public EntityDomainType getReferencedPathSource() { + return treatTarget; + } + @Override public SqmPath resolveIndexedAccess( SqmExpression selector, 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 75e1391039..ba3f42701a 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 @@ -73,6 +73,11 @@ public class SqmTreatedMapJoin extends SqmMapJoin return treatTarget; } + @Override + public EntityDomainType getReferencedPathSource() { + return treatTarget; + } + @Override public SqmMapJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmTreatedMapJoin<>( 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 b8c5a11f6e..51cad5bf11 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 @@ -65,11 +65,6 @@ public class SqmTreatedSetJoin extends SqmSetJoin impleme return wrappedPath; } - @Override - public SetPersistentAttribute getModel() { - return super.getModel(); - } - @Override public EntityDomainType getTreatTarget() { return treatTarget; @@ -81,8 +76,8 @@ public class SqmTreatedSetJoin extends SqmSetJoin impleme } @Override - public SetPersistentAttribute getReferencedPathSource() { - return super.getReferencedPathSource(); + public EntityDomainType getReferencedPathSource() { + return treatTarget; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSingularJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSingularJoin.java index 7002ef898b..a7abbfe150 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSingularJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmTreatedSingularJoin.java @@ -75,6 +75,11 @@ public class SqmTreatedSingularJoin extends SqmSingularJoin getReferencedPathSource() { + return getTreatTarget(); + } + @Override public SqmAttributeJoin makeCopy(SqmCreationProcessingState creationProcessingState) { return new SqmTreatedSingularJoin<>( wrappedPath, treatTarget, getAlias() );