Skip to content

Commit fccbb8d

Browse files
committed
HHH-18628 Regression: Unable to determine TableReference
1 parent a54d7ec commit fccbb8d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static boolean isFkOptimizationAllowed(SqmPath<?> sqmPath) {
246246
* or one that has an explicit on clause predicate.
247247
*/
248248
public static boolean isFkOptimizationAllowed(SqmPath<?> sqmPath, EntityAssociationMapping associationMapping) {
249-
if ( sqmPath instanceof SqmJoin<?, ?> sqmJoin ) {
249+
if ( associationMapping.isFkOptimizationAllowed() && sqmPath instanceof SqmJoin<?, ?> sqmJoin ) {
250250
switch ( sqmJoin.getSqmJoinType() ) {
251251
case LEFT:
252252
if ( isFiltered( associationMapping ) ) {

hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4140,12 +4140,11 @@ private Expression visitTableGroup(TableGroup tableGroup, SqmPath<?> path) {
41404140
if ( inferredEntityMapping == null ) {
41414141
// When the inferred mapping is null, we try to resolve to the FK by default, which is fine because
41424142
// expansion to all target columns for select and group by clauses is handled in EntityValuedPathInterpretation
4143-
if ( entityValuedModelPart instanceof EntityAssociationMapping
4144-
&& isFkOptimizationAllowed( path, (EntityAssociationMapping) entityValuedModelPart ) ) {
4143+
if ( entityValuedModelPart instanceof EntityAssociationMapping associationMapping
4144+
&& isFkOptimizationAllowed( path, associationMapping ) ) {
41454145
// If the table group uses an association mapping that is not a one-to-many,
41464146
// we make use of the FK model part - unless the path is a non-optimizable join,
41474147
// for which we should always use the target's identifier to preserve semantics
4148-
final EntityAssociationMapping associationMapping = (EntityAssociationMapping) entityValuedModelPart;
41494148
final ModelPart targetPart = associationMapping.getForeignKeyDescriptor().getPart(
41504149
associationMapping.getSideNature()
41514150
);

0 commit comments

Comments
 (0)