HHH-15260 Criteria query is unable to determine TableReference when combining subquery with join

This commit is contained in:
Andrea Boriero 2022-05-10 16:27:35 +02:00 committed by Andrea Boriero
parent f0cb0e8f78
commit e29884b764
3 changed files with 9 additions and 1 deletions

View File

@ -1637,7 +1637,7 @@ public class ToOneAttributeMapping
return false;
}
if ( navigablePath.equals( np.getParent() ) ) {
if ( navigablePath.pathsMatch( np.getParent() ) ) {
return targetKeyPropertyNames.contains( np.getLocalName() );
}

View File

@ -3108,6 +3108,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
else {
tableGroup = compatibleTableGroup;
// Also register the table group under its original navigable path, which possibly contains an alias
// This is important, as otherwise we might create new joins in subqueries which are unnecessary
fromClauseIndex.registerTableGroup( tableGroup.getNavigablePath(), tableGroup );
}
}

View File

@ -191,6 +191,11 @@ public class NavigablePath implements DotIdentifierSequence, Serializable {
return false;
}
public boolean pathsMatch(NavigablePath p) {
return this == p || p != null && localName.equals( p.localName )
&& ( parent == null ? p.parent == null && Objects.equals( alias, p.alias ) : parent.pathsMatch( p.parent ) );
}
/**
* Ignores aliases in the resulting String
*/