Skip to content

Commit 7c5e419

Browse files
mbelladebeikov
authored andcommitted
HHH-17606 Fix nested generic join path resolution
1 parent d41981e commit 7c5e419

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

hibernate-core/src/main/java/org/hibernate/query/hql/internal/QualifiedJoinPathConsumer.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,7 @@ private static SqmFrom<?, Object> createJoin(
178178
boolean isTerminal,
179179
boolean allowReuse,
180180
SqmCreationState creationState) {
181-
final SqmPathSource<?> referencedPathSource = lhs.getReferencedPathSource();
182-
// We need to use referencedPathSource when it is not generic since the getResolvedModel() method would
183-
// return the association attribute as a path source and for treated paths that might correspond to a
184-
// different entity type (usually the first in alphabetical order) and not the correct treat target
185-
final SqmPathSource<?> pathSource = referencedPathSource.isGeneric() ?
186-
lhs.getResolvedModel() :
187-
referencedPathSource;
188-
//noinspection unchecked
189-
final SqmPathSource<Object> subPathSource = (SqmPathSource<Object>) pathSource.getSubPathSource( name );
181+
final SqmPathSource<?> subPathSource = lhs.getResolvedModel().getSubPathSource( name );
190182
if ( allowReuse && !isTerminal ) {
191183
for ( SqmJoin<?, ?> sqmJoin : lhs.getSqmJoins() ) {
192184
if ( sqmJoin.getAlias() == null && sqmJoin.getReferencedPathSource() == subPathSource ) {

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ public SqmPathSource<T> getModel() {
161161
public SqmPathSource<?> getResolvedModel() {
162162
final DomainType<?> lhsType;
163163
final SqmPathSource<T> pathSource = getReferencedPathSource();
164-
if ( pathSource.isGeneric() && ( lhsType = getLhs().getReferencedPathSource()
165-
.getSqmPathType() ) instanceof ManagedDomainType ) {
164+
if ( pathSource.isGeneric() && ( lhsType = getLhs().getResolvedModel().getSqmPathType() ) instanceof ManagedDomainType ) {
166165
final PersistentAttribute<?, ?> concreteAttribute = ( (ManagedDomainType<?>) lhsType ).findConcreteGenericAttribute(
167166
pathSource.getPathName()
168167
);

0 commit comments

Comments
 (0)