From 383653d5d475a63c886b39b5040788efb840fd08 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 27 Sep 2023 14:35:53 +0200 Subject: [PATCH] HHH-16885 Hibernate 6.x changes outer to inner join when @EntityGraph and @Id --- .../AbstractCompositeIdentifierMapping.java | 9 ++------ .../internal/PluralAttributeMappingImpl.java | 21 ++----------------- .../internal/ToOneAttributeMapping.java | 16 -------------- .../ast/tree/from/TableGroupJoinProducer.java | 16 ++++++++++++++ 4 files changed, 20 insertions(+), 42 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java index 3ff4da72e5..15cc096d93 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java @@ -126,13 +126,7 @@ public abstract class AbstractCompositeIdentifierMapping boolean fetched, boolean addsPredicate, SqlAstCreationState creationState) { - final SqlAstJoinType joinType; - if ( requestedJoinType == null ) { - joinType = SqlAstJoinType.INNER; - } - else { - joinType = requestedJoinType; - } + final SqlAstJoinType joinType = determineSqlJoinType( lhs, requestedJoinType, fetched ); final TableGroup tableGroup = createRootTableGroupJoin( navigablePath, lhs, @@ -295,4 +289,5 @@ public abstract class AbstractCompositeIdentifierMapping public boolean containsTableReference(String tableExpression) { return entityMapping.containsTableReference( tableExpression ); } + } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java index 7859d6f276..223dacfb52 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java @@ -680,22 +680,6 @@ public class PluralAttributeMappingImpl ); } - private SqlAstJoinType determineSqlJoinType(TableGroup lhs, SqlAstJoinType requestedJoinType, boolean fetched) { - final SqlAstJoinType joinType; - if ( requestedJoinType == null ) { - if ( fetched ) { - joinType = getDefaultSqlAstJoinType( lhs ); - } - else { - joinType = SqlAstJoinType.INNER; - } - } - else { - joinType = requestedJoinType; - } - return joinType; - } - @Override public TableGroup createRootTableGroupJoin( NavigablePath navigablePath, @@ -707,9 +691,7 @@ public class PluralAttributeMappingImpl Consumer predicateConsumer, SqlAstCreationState creationState) { final CollectionPersister collectionDescriptor = getCollectionDescriptor(); - final SqlAstJoinType joinType = requestedJoinType == null - ? SqlAstJoinType.INNER - : requestedJoinType; + final SqlAstJoinType joinType = determineSqlJoinType( lhs, requestedJoinType, fetched ); final SqlAliasBase sqlAliasBase = creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() ); final TableGroup tableGroup; @@ -741,6 +723,7 @@ public class PluralAttributeMappingImpl return tableGroup; } + @Override public void setForeignKeyDescriptor(ForeignKeyDescriptor fkDescriptor) { this.fkDescriptor = fkDescriptor; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index 60152823c3..33cb653225 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -1991,22 +1991,6 @@ public class ToOneAttributeMapping return join; } - private SqlAstJoinType determineSqlJoinType(TableGroup lhs, SqlAstJoinType requestedJoinType, boolean fetched) { - final SqlAstJoinType joinType; - if ( requestedJoinType == null ) { - if ( fetched ) { - joinType = getDefaultSqlAstJoinType( lhs ); - } - else { - joinType = SqlAstJoinType.INNER; - } - } - else { - joinType = requestedJoinType; - } - return joinType; - } - @Override public LazyTableGroup createRootTableGroupJoin( NavigablePath navigablePath, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoinProducer.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoinProducer.java index e19245d43f..52cb68bc3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoinProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoinProducer.java @@ -76,4 +76,20 @@ public interface TableGroupJoinProducer extends TableGroupProducer { boolean fetched, Consumer predicateConsumer, SqlAstCreationState creationState); + + default SqlAstJoinType determineSqlJoinType(TableGroup lhs, SqlAstJoinType requestedJoinType, boolean fetched) { + final SqlAstJoinType joinType; + if ( requestedJoinType == null ) { + if ( fetched ) { + joinType = getDefaultSqlAstJoinType( lhs ); + } + else { + joinType = SqlAstJoinType.INNER; + } + } + else { + joinType = requestedJoinType; + } + return joinType; + } }