Skip to content

Commit

Permalink
HHH-17606 Fix nested generic join path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel authored and beikov committed Jan 4, 2024
1 parent 0195a77 commit 942e5cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ private AttributeJoinDelegate resolveAlias(String identifier, boolean isTerminal
boolean isTerminal,
boolean allowReuse,
SqmCreationState creationState) {
final SqmPathSource<?> subPathSource = subPathSource( lhs, name, creationState );
final SqmPathSource<?> subPathSource = lhs.getResolvedModel().getSubPathSource(
name,
creationState.getCreationContext().getJpaMetamodel()
);
if ( allowReuse && !isTerminal ) {
for ( SqmJoin<?, ?> sqmJoin : lhs.getSqmJoins() ) {
if ( sqmJoin.getAlias() == null && sqmJoin.getReferencedPathSource() == subPathSource ) {
Expand All @@ -200,18 +203,6 @@ private AttributeJoinDelegate resolveAlias(String identifier, boolean isTerminal
return createJoin( lhs, joinType, alias, fetch, isTerminal, allowReuse, creationState, joinSource );
}

private static <U> SqmPathSource<?> subPathSource(SqmFrom<?, U> lhs, String name, SqmCreationState creationState) {
final SqmPathSource<U> 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;
return pathSource.getSubPathSource( name, creationState.getCreationContext().getJpaMetamodel() );
}

private static <U,V> SqmFrom<?, ?> createJoin(
SqmFrom<?,U> lhs,
SqmJoinType joinType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ public SqmPathSource<T> getModel() {
public SqmPathSource<?> getResolvedModel() {
final DomainType<?> lhsType;
final SqmPathSource<T> 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()
);
Expand Down

0 comments on commit 942e5cd

Please sign in to comment.