HHH-18628 Regression: Unable to determine TableReference

This commit is contained in:
Andrea Boriero 2024-09-18 11:24:14 +02:00 committed by Andrea Boriero
parent a54d7ec804
commit fccbb8d582
2 changed files with 3 additions and 4 deletions

View File

@ -246,7 +246,7 @@ public class SqmUtil {
* or one that has an explicit on clause predicate.
*/
public static boolean isFkOptimizationAllowed(SqmPath<?> sqmPath, EntityAssociationMapping associationMapping) {
if ( sqmPath instanceof SqmJoin<?, ?> sqmJoin ) {
if ( associationMapping.isFkOptimizationAllowed() && sqmPath instanceof SqmJoin<?, ?> sqmJoin ) {
switch ( sqmJoin.getSqmJoinType() ) {
case LEFT:
if ( isFiltered( associationMapping ) ) {

View File

@ -4140,12 +4140,11 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
if ( inferredEntityMapping == null ) {
// When the inferred mapping is null, we try to resolve to the FK by default, which is fine because
// expansion to all target columns for select and group by clauses is handled in EntityValuedPathInterpretation
if ( entityValuedModelPart instanceof EntityAssociationMapping
&& isFkOptimizationAllowed( path, (EntityAssociationMapping) entityValuedModelPart ) ) {
if ( entityValuedModelPart instanceof EntityAssociationMapping associationMapping
&& isFkOptimizationAllowed( path, associationMapping ) ) {
// If the table group uses an association mapping that is not a one-to-many,
// we make use of the FK model part - unless the path is a non-optimizable join,
// for which we should always use the target's identifier to preserve semantics
final EntityAssociationMapping associationMapping = (EntityAssociationMapping) entityValuedModelPart;
final ModelPart targetPart = associationMapping.getForeignKeyDescriptor().getPart(
associationMapping.getSideNature()
);