From 7c5e419c29d540fda1f9e3def41b26b3c271506d Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 2 Jan 2024 11:38:49 +0100 Subject: [PATCH] HHH-17606 Fix nested generic join path resolution --- .../query/hql/internal/QualifiedJoinPathConsumer.java | 10 +--------- .../query/sqm/tree/domain/AbstractSqmPath.java | 3 +-- 2 files changed, 2 insertions(+), 11 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 53fe409e40..494c318ac4 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,15 +178,7 @@ 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) pathSource.getSubPathSource( name ); + final SqmPathSource subPathSource = lhs.getResolvedModel().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/sqm/tree/domain/AbstractSqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java index 23ad82d30b..d7d3a7f0ae 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 @@ -161,8 +161,7 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem public SqmPathSource getResolvedModel() { final DomainType lhsType; final SqmPathSource pathSource = getReferencedPathSource(); - if ( pathSource.isGeneric() && ( lhsType = getLhs().getReferencedPathSource() - .getSqmPathType() ) instanceof ManagedDomainType ) { + if ( pathSource.isGeneric() && ( lhsType = getLhs().getResolvedModel().getSqmPathType() ) instanceof ManagedDomainType ) { final PersistentAttribute concreteAttribute = ( (ManagedDomainType) lhsType ).findConcreteGenericAttribute( pathSource.getPathName() );