From 241300c0c112577d8ca69f6ac4e76221f54fcffb Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 6 Jul 2021 16:22:17 +0200 Subject: [PATCH] Fix wrong creation of inner join --- .../dialect/InformixSqmToSqlAstConverter.java | 1 + .../dialect/IngresSqmToSqlAstConverter.java | 1 + .../dialect/SybaseSqmToSqlAstConverter.java | 1 + .../ast/internal/AbstractNaturalIdLoader.java | 1 + .../internal/DatabaseSnapshotExecutor.java | 2 ++ .../ast/internal/LoaderSelectBuilder.java | 3 +++ .../hibernate/loader/ast/spi/Loadable.java | 1 + .../mapping/EntityAssociationMapping.java | 1 + .../metamodel/mapping/EntityMappingType.java | 2 ++ .../internal/PluralAttributeMappingImpl.java | 12 +++++++++-- .../internal/SimpleForeignKeyDescriptor.java | 1 - .../internal/ToOneAttributeMapping.java | 20 +++++++++++++++---- .../entity/AbstractEntityPersister.java | 2 ++ .../entity/SingleTableEntityPersister.java | 2 ++ .../entity/UnionSubclassEntityPersister.java | 3 ++- .../query/results/TableGroupImpl.java | 9 ++------- .../CompleteResultBuilderEntityJpa.java | 1 + .../CompleteResultBuilderEntityStandard.java | 1 + .../ImplicitModelPartResultBuilderEntity.java | 1 + .../MultiTableSqmMutationConverter.java | 1 + .../idtable/ExecuteWithIdTableHelper.java | 1 + .../idtable/ExecuteWithoutIdTableHelper.java | 1 + .../sqm/sql/BaseSqmToSqlAstConverter.java | 13 ++++++++++++ .../hibernate/sql/ast/tree/cte/CteTable.java | 1 + .../sql/ast/tree/cte/CteTableGroup.java | 3 +-- .../sql/ast/tree/from/AbstractTableGroup.java | 15 +++++++------- .../ast/tree/from/CompositeTableGroup.java | 10 ++++------ .../ast/tree/from/CorrelatedTableGroup.java | 3 ++- .../sql/ast/tree/from/LazyTableGroup.java | 11 +++++----- .../MutatingTableReferenceGroupWrapper.java | 3 +-- .../ast/tree/from/RootTableGroupProducer.java | 1 + .../sql/ast/tree/from/StandardTableGroup.java | 13 +++++++++--- .../sql/ast/tree/from/TableGroup.java | 4 +--- .../sql/ast/tree/from/UnionTableGroup.java | 12 +++++------ .../EntityCollectionPartTableGroup.java | 4 ++-- .../internal/EmbeddableResultImpl.java | 4 +++- 36 files changed, 110 insertions(+), 55 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqmToSqlAstConverter.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqmToSqlAstConverter.java index 63fecaa3f9..ca607f1fe4 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqmToSqlAstConverter.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqmToSqlAstConverter.java @@ -50,6 +50,7 @@ public class InformixSqmToSqlAstConverter extends BaseSqmTo if ( this.needsDummyTableGroup ) { querySpec.getFromClause().addRoot( new StandardTableGroup( + false, null, null, null, diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresSqmToSqlAstConverter.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresSqmToSqlAstConverter.java index 9f97c090b2..b36639fd08 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresSqmToSqlAstConverter.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresSqmToSqlAstConverter.java @@ -50,6 +50,7 @@ public class IngresSqmToSqlAstConverter extends BaseSqmToSq if ( this.needsDummyTableGroup ) { querySpec.getFromClause().addRoot( new StandardTableGroup( + false, null, null, null, diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseSqmToSqlAstConverter.java index 2d3768ae68..7aef709eba 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseSqmToSqlAstConverter.java @@ -50,6 +50,7 @@ public class SybaseSqmToSqlAstConverter extends BaseSqmToSq if ( this.needsDummyTableGroup ) { querySpec.getFromClause().addRoot( new StandardTableGroup( + true, null, null, null, diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java index 1ac85c287c..7326444026 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java @@ -177,6 +177,7 @@ public abstract class AbstractNaturalIdLoader implements NaturalIdLoader { ); final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup( + true, entityPath, null, () -> rootQuerySpec::applyPredicate, diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java index b1e17755c1..102838ed3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/DatabaseSnapshotExecutor.java @@ -89,6 +89,7 @@ class DatabaseSnapshotExecutor { final NavigablePath rootPath = new NavigablePath( entityDescriptor.getEntityName() ); final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup( + true, rootPath, null, () -> rootQuerySpec::applyPredicate, @@ -146,6 +147,7 @@ class DatabaseSnapshotExecutor { if ( contributorMapping instanceof EntityAssociationMapping ) { domainResults.add( ( (EntityAssociationMapping) contributorMapping ).createDelayedDomainResult( + true, navigablePath, rootTableGroup, null, diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java index c47079378f..396a4f4fcb 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java @@ -386,6 +386,7 @@ public class LoaderSelectBuilder { ); final TableGroup rootTableGroup = loadable.createRootTableGroup( + true, rootNavigablePath, null, () -> rootQuerySpec::applyPredicate, @@ -403,6 +404,7 @@ public class LoaderSelectBuilder { final TableGroup tableGroup; if ( part instanceof RootTableGroupProducer ) { tableGroup = ( (RootTableGroupProducer) part ).createRootTableGroup( + true, navigablePath, null, () -> rootQuerySpec::applyPredicate, @@ -920,6 +922,7 @@ public class LoaderSelectBuilder { // to control how that gets rendered in the walker final TableGroup rootTableGroup = loadable.createRootTableGroup( + true, rootNavigablePath, null, () -> rootQuerySpec::applyPredicate, diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/spi/Loadable.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/spi/Loadable.java index 5dbe465b99..ef1a6403fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/spi/Loadable.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/spi/Loadable.java @@ -37,6 +37,7 @@ public interface Loadable extends ModelPart, RootTableGroupProducer { @Override default TableGroup createRootTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, String explicitSourceAlias, Supplier> additionalPredicateCollectorAccess, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityAssociationMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityAssociationMapping.java index f250525911..d17e6591b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityAssociationMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityAssociationMapping.java @@ -41,6 +41,7 @@ public interface EntityAssociationMapping extends ModelPart, Association, TableG * Create a delayed DomainResult for a specific reference to this ModelPart. */ default DomainResult createDelayedDomainResult( + boolean canUseInnerJoins, NavigablePath navigablePath, TableGroup tableGroup, String resultVariable, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java index 15528dde32..f2b9f4fff7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityMappingType.java @@ -276,12 +276,14 @@ public interface EntityMappingType extends ManagedMappingType, EntityValuedModel @Override default TableGroup createRootTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, String explicitSourceAlias, Supplier> additionalPredicateCollectorAccess, SqlAstCreationState creationState, SqlAstCreationContext creationContext) { return getEntityPersister().createRootTableGroup( + canUseInnerJoins, navigablePath, explicitSourceAlias, additionalPredicateCollectorAccess, 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 6b0c8d61e6..82f9bea76b 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 @@ -24,7 +24,6 @@ import org.hibernate.mapping.Collection; import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.IndexedConsumer; import org.hibernate.mapping.List; -import org.hibernate.mapping.OneToOne; import org.hibernate.mapping.Property; import org.hibernate.mapping.Value; import org.hibernate.metamodel.mapping.BasicValuedModelPart; @@ -38,7 +37,6 @@ import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.PluralAttributeMapping; -import org.hibernate.metamodel.mapping.PropertyBasedMapping; import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess; import org.hibernate.metamodel.mapping.ordering.OrderByFragment; @@ -610,6 +608,7 @@ public class PluralAttributeMappingImpl SqlExpressionResolver sqlExpressionResolver, SqlAstCreationContext creationContext) { final TableGroup tableGroup = createOneToManyTableGroup( + lhs.canUseInnerJoins(), navigablePath, fetched, explicitSourceAlias, @@ -637,6 +636,7 @@ public class PluralAttributeMappingImpl } private TableGroup createOneToManyTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, String sourceAlias, @@ -678,6 +678,7 @@ public class PluralAttributeMappingImpl ); return new StandardTableGroup( + canUseInnerJoins, navigablePath, this, fetched, @@ -751,6 +752,7 @@ public class PluralAttributeMappingImpl }; return new StandardTableGroup( + canUseInnerJoins, navigablePath, this, fetched, @@ -775,6 +777,7 @@ public class PluralAttributeMappingImpl SqlExpressionResolver sqlExpressionResolver, SqlAstCreationContext creationContext) { final TableGroup tableGroup = createCollectionTableGroup( + lhs.canUseInnerJoins(), navigablePath, fetched, explicitSourceAlias, @@ -802,6 +805,7 @@ public class PluralAttributeMappingImpl } private TableGroup createCollectionTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, String sourceAlias, @@ -930,6 +934,7 @@ public class PluralAttributeMappingImpl } final StandardTableGroup tableGroup = new StandardTableGroup( + canUseInnerJoins, navigablePath, this, fetched, @@ -1015,6 +1020,7 @@ public class PluralAttributeMappingImpl @Override public TableGroup createRootTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, String explicitSourceAlias, Supplier> additionalPredicateCollectorAccess, @@ -1022,6 +1028,7 @@ public class PluralAttributeMappingImpl SqlAstCreationContext creationContext) { if ( getCollectionDescriptor().isOneToMany() ) { return createOneToManyTableGroup( + canUseInnerJoins, navigablePath, false, explicitSourceAlias, @@ -1032,6 +1039,7 @@ public class PluralAttributeMappingImpl } else { return createCollectionTableGroup( + canUseInnerJoins, navigablePath, false, explicitSourceAlias, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java index 37035ddc31..d7ae806eaa 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java @@ -8,7 +8,6 @@ package org.hibernate.metamodel.mapping.internal; import java.util.Collections; import java.util.List; -import java.util.function.Function; import java.util.function.IntFunction; import org.hibernate.engine.FetchStyle; 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 da1cebf987..2cea2ae342 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 @@ -657,7 +657,13 @@ public class ToOneAttributeMapping tableGroup = fromClauseAccess.resolveTableGroup( fetchablePath, np -> - createTableGroupJoin( fetchablePath, true, resultVariable, creationState, parentTableGroup ) + createTableGroupJoin( + fetchablePath, + true, + resultVariable, + creationState, + parentTableGroup + ) ); } @@ -744,6 +750,7 @@ public class ToOneAttributeMapping @Override public DomainResult createDelayedDomainResult( + boolean canUseInnerJoins, NavigablePath navigablePath, TableGroup tableGroup, String resultVariable, @@ -808,10 +815,10 @@ public class ToOneAttributeMapping return SqlAstJoinType.LEFT; } else { - if ( parentTableGroup.isOuterJoined() ) { - return SqlAstJoinType.LEFT; + if ( parentTableGroup.canUseInnerJoins() ) { + return SqlAstJoinType.INNER; } - return SqlAstJoinType.INNER; + return SqlAstJoinType.LEFT; } } @@ -850,9 +857,12 @@ public class ToOneAttributeMapping SqlExpressionResolver sqlExpressionResolver, SqlAstCreationContext creationContext) { final SqlAliasBase sqlAliasBase = aliasBaseGenerator.createSqlAliasBase( sqlAliasStem ); + boolean canUseInnerJoin = lhs.canUseInnerJoins() && sqlAstJoinType == SqlAstJoinType.INNER; final LazyTableGroup lazyTableGroup = new LazyTableGroup( + canUseInnerJoin, navigablePath, () -> createTableGroupJoinInternal( + canUseInnerJoin, navigablePath, fetched, null, @@ -927,6 +937,7 @@ public class ToOneAttributeMapping } public TableGroup createTableGroupJoinInternal( + boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, String sourceAlias, @@ -940,6 +951,7 @@ public class ToOneAttributeMapping ); return new StandardTableGroup( + canUseInnerJoins, navigablePath, this, fetched, diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index add0c50b94..8f6c7ff096 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -1367,6 +1367,7 @@ public abstract class AbstractEntityPersister @Override public TableGroup createRootTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, String explicitSourceAlias, Supplier> additionalPredicateCollectorAccess, @@ -1383,6 +1384,7 @@ public abstract class AbstractEntityPersister ); return new StandardTableGroup( + canUseInnerJoins, navigablePath, this, explicitSourceAlias, diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index d40d2b76ea..cebd06fcbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -927,12 +927,14 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { @Override public TableGroup createRootTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, String explicitSourceAlias, Supplier> additionalPredicateCollectorAccess, SqlAstCreationState creationState, SqlAstCreationContext creationContext) { final TableGroup tableGroup = super.createRootTableGroup( + canUseInnerJoins, navigablePath, explicitSourceAlias, additionalPredicateCollectorAccess, diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java index 8bc46bfd86..fe29d1e443 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/UnionSubclassEntityPersister.java @@ -241,6 +241,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { @Override public TableGroup createRootTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, String explicitSourceAlias, Supplier> additionalPredicateCollectorAccess, @@ -250,7 +251,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister { final TableReference tableReference = resolvePrimaryTableReference(sqlAliasBase); - return new UnionTableGroup( navigablePath, tableReference, this, explicitSourceAlias ); + return new UnionTableGroup( canUseInnerJoins, navigablePath, tableReference, this, explicitSourceAlias ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/TableGroupImpl.java b/hibernate-core/src/main/java/org/hibernate/query/results/TableGroupImpl.java index c61ab30ebd..174569d4d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/TableGroupImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/TableGroupImpl.java @@ -13,7 +13,6 @@ import java.util.function.Consumer; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.query.NavigablePath; -import org.hibernate.sql.ast.SqlAstJoinType; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.ast.tree.from.TableReference; @@ -33,7 +32,6 @@ public class TableGroupImpl implements TableGroup { private final ModelPartContainer container; private final String sourceAlias; - private boolean isOuterJoined; public TableGroupImpl( NavigablePath navigablePath, @@ -79,8 +77,8 @@ public class TableGroupImpl implements TableGroup { } @Override - public boolean isOuterJoined() { - return isOuterJoined; + public boolean canUseInnerJoins() { + return false; } @Override @@ -93,9 +91,6 @@ public class TableGroupImpl implements TableGroup { if ( tableGroupJoins == null ) { tableGroupJoins = new ArrayList<>(); } - if ( join.getJoinType() != SqlAstJoinType.INNER ) { - isOuterJoined = true; - } if ( !tableGroupJoins.contains( join ) ) { tableGroupJoins.add( join ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java index f09d4301d4..ef0a9f8ce4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityJpa.java @@ -79,6 +79,7 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti impl.getFromClauseAccess().resolveTableGroup( navigablePath, np -> entityDescriptor.createRootTableGroup( + true, navigablePath, null, () -> predicate -> {}, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java index 489a01170f..b742cbc6e2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderEntityStandard.java @@ -71,6 +71,7 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde impl.getFromClauseAccess().resolveTableGroup( navigablePath, np -> entityDescriptor.createRootTableGroup( + true, navigablePath, null, () -> predicate -> {}, diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitModelPartResultBuilderEntity.java b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitModelPartResultBuilderEntity.java index e9a4858fe7..4ffdfda2a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitModelPartResultBuilderEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitModelPartResultBuilderEntity.java @@ -57,6 +57,7 @@ public class ImplicitModelPartResultBuilderEntity } return modelPart.getEntityMappingType().createRootTableGroup( + true, navigablePath, null, () -> predicate -> { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MultiTableSqmMutationConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MultiTableSqmMutationConverter.java index f02a2e91f7..6568e997d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MultiTableSqmMutationConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/MultiTableSqmMutationConverter.java @@ -103,6 +103,7 @@ public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter predicate -> { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithIdTableHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithIdTableHelper.java index f99d244188..5de0370ae0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithIdTableHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithIdTableHelper.java @@ -173,6 +173,7 @@ public final class ExecuteWithIdTableHelper { executionContext.getSession().getFactory() ); final TableGroup idTableGroup = new StandardTableGroup( + true, new NavigablePath( idTableReference.getTableExpression() ), entityDescriptor, null, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithoutIdTableHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithoutIdTableHelper.java index f8f53d038d..5d85c78354 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithoutIdTableHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/ExecuteWithoutIdTableHelper.java @@ -39,6 +39,7 @@ public final class ExecuteWithoutIdTableHelper { final QuerySpec matchingIdSelect = new QuerySpec( false, 1 ); final StandardTableGroup matchingIdSelectTableGroup = new StandardTableGroup( + true, navigablePath, rootEntityPersister, rootTableReference.getIdentificationVariable(), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index b3c29e8b16..8d5091834b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -593,6 +593,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base try { final NavigablePath rootPath = sqmTarget.getNavigablePath(); final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup( + true, rootPath, sqmStatement.getRoot().getAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ), @@ -850,6 +851,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base try { final NavigablePath rootPath = statement.getTarget().getNavigablePath(); final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup( + true, rootPath, statement.getRoot().getAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ), @@ -932,6 +934,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base try { final NavigablePath rootPath = sqmStatement.getTarget().getNavigablePath(); final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup( + true, rootPath, sqmStatement.getTarget().getExplicitAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ), @@ -1030,6 +1033,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base try { final NavigablePath rootPath = sqmStatement.getTarget().getNavigablePath(); final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup( + true, rootPath, sqmStatement.getTarget().getExplicitAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ), @@ -1831,6 +1835,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base // If we have just inner joins against a correlated root, we can render the joins as references final SqlAliasBase sqlAliasBase = sqlAliasBaseManager.createSqlAliasBase( parentTableGroup.getGroupAlias() ); tableGroup = new CorrelatedTableGroup( + parentTableGroup.canUseInnerJoins(), parentTableGroup, sqlAliasBase, currentQuerySpec(), @@ -1850,6 +1855,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base else { // If we have non-inner joins against a correlated root, we must render the root with a correlation predicate tableGroup = entityDescriptor.createRootTableGroup( + true, sqmRoot.getNavigablePath(), sqmRoot.getExplicitAlias(), () -> predicate -> {}, @@ -1914,6 +1920,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base else { final EntityPersister entityDescriptor = resolveEntityPersister( sqmRoot.getReferencedPathSource() ); tableGroup = entityDescriptor.createRootTableGroup( + true, sqmRoot.getNavigablePath(), sqmRoot.getExplicitAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( @@ -2066,6 +2073,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base final EntityPersister entityDescriptor = resolveEntityPersister( sqmJoin.getReferencedPathSource() ); final TableGroup tableGroup = entityDescriptor.createRootTableGroup( + true, sqmJoin.getNavigablePath(), sqmJoin.getExplicitAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( @@ -2094,6 +2102,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base final EntityPersister entityDescriptor = resolveEntityPersister( sqmJoin.getReferencedPathSource() ); final TableGroup tableGroup = entityDescriptor.createRootTableGroup( + true, sqmJoin.getNavigablePath(), sqmJoin.getExplicitAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( @@ -3949,6 +3958,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base ); try { final TableGroup tableGroup = collectionPart.createRootTableGroup( + true, pluralPath.getNavigablePath(), null, () -> subQuerySpec::applyPredicate, @@ -4017,6 +4027,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base ); try { final TableGroup tableGroup = mappingModelExpressable.createRootTableGroup( + true, pluralPartPath.getNavigablePath(), null, () -> subQuerySpec::applyPredicate, @@ -4165,6 +4176,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base ); try { final TableGroup tableGroup = mappingModelExpressable.createRootTableGroup( + true, pluralPath.getNavigablePath(), null, () -> subQuerySpec::applyPredicate, @@ -4269,6 +4281,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base final TableGroup parentTableGroup = parentFromClauseAccess.getTableGroup( parentNavPath ); final SqlAliasBase sqlAliasBase = sqlAliasBaseManager.createSqlAliasBase( parentTableGroup.getGroupAlias() ); final TableGroup tableGroup = new CorrelatedTableGroup( + parentTableGroup.canUseInnerJoins(), parentTableGroup, sqlAliasBase, subQuerySpec, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTable.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTable.java index b1d137a498..7bed61879f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTable.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTable.java @@ -78,6 +78,7 @@ public class CteTable { ); final StandardTableGroup tableValueCtorGroup = new StandardTableGroup( + true, new NavigablePath( "cte" ), null, null, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTableGroup.java index 7c2b6342e5..71cb2f3a5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/CteTableGroup.java @@ -10,7 +10,6 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; -import org.hibernate.LockMode; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.query.NavigablePath; @@ -61,7 +60,7 @@ public class CteTableGroup implements TableGroup { } @Override - public boolean isOuterJoined() { + public boolean canUseInnerJoins() { return false; } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java index 48ecc1ad1f..b9c996719f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java @@ -14,7 +14,6 @@ import java.util.function.Consumer; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.query.NavigablePath; -import org.hibernate.sql.ast.SqlAstJoinType; import org.hibernate.sql.ast.spi.SqlAliasBase; /** @@ -28,22 +27,24 @@ public abstract class AbstractTableGroup extends AbstractColumnReferenceQualifie private List tableGroupJoins; private boolean isInnerJoinPossible; - private boolean isOuterJoined; + private boolean canUseInnerJoins; private final SessionFactoryImplementor sessionFactory; @SuppressWarnings("WeakerAccess") public AbstractTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, TableGroupProducer producer, String sourceAlias, SqlAliasBase sqlAliasBase, SessionFactoryImplementor sessionFactory) { - this( navigablePath, producer, sourceAlias, sqlAliasBase, false, sessionFactory ); + this( canUseInnerJoins, navigablePath, producer, sourceAlias, sqlAliasBase, false, sessionFactory ); } @SuppressWarnings("WeakerAccess") public AbstractTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, TableGroupProducer producer, String sourceAlias, @@ -51,6 +52,7 @@ public abstract class AbstractTableGroup extends AbstractColumnReferenceQualifie boolean isInnerJoinPossible, SessionFactoryImplementor sessionFactory) { super(); + this.canUseInnerJoins = canUseInnerJoins; this.navigablePath = navigablePath; this.producer = producer; this.sourceAlias = sourceAlias; @@ -99,8 +101,8 @@ public abstract class AbstractTableGroup extends AbstractColumnReferenceQualifie } @Override - public boolean isOuterJoined() { - return isOuterJoined; + public boolean canUseInnerJoins() { + return canUseInnerJoins; } @Override @@ -113,9 +115,6 @@ public abstract class AbstractTableGroup extends AbstractColumnReferenceQualifie if ( tableGroupJoins == null ) { tableGroupJoins = new ArrayList<>(); } - if ( join.getJoinType() != SqlAstJoinType.INNER ) { - isOuterJoined = true; - } if ( !tableGroupJoins.contains( join ) ) { tableGroupJoins.add( join ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java index 52e8c17425..cd7e2c361f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CompositeTableGroup.java @@ -25,12 +25,13 @@ public class CompositeTableGroup implements VirtualTableGroup { private final TableGroup underlyingTableGroup; private List tableGroupJoins; - private boolean isOuterJoined; + private final boolean canUseInnerJoins; public CompositeTableGroup( NavigablePath navigablePath, EmbeddableValuedModelPart compositionMapping, TableGroup underlyingTableGroup) { + this.canUseInnerJoins = underlyingTableGroup.canUseInnerJoins(); this.navigablePath = navigablePath; this.compositionMapping = compositionMapping; this.underlyingTableGroup = underlyingTableGroup; @@ -68,8 +69,8 @@ public class CompositeTableGroup implements VirtualTableGroup { } @Override - public boolean isOuterJoined() { - return isOuterJoined; + public boolean canUseInnerJoins() { + return canUseInnerJoins; } @Override @@ -82,9 +83,6 @@ public class CompositeTableGroup implements VirtualTableGroup { if ( tableGroupJoins == null ) { tableGroupJoins = new ArrayList<>(); } - if ( join.getJoinType() != SqlAstJoinType.INNER ) { - isOuterJoined = true; - } if ( !tableGroupJoins.contains( join ) ) { tableGroupJoins.add( join ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CorrelatedTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CorrelatedTableGroup.java index e756fb46f4..117f545e14 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CorrelatedTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/CorrelatedTableGroup.java @@ -25,18 +25,19 @@ import org.hibernate.sql.ast.tree.select.QuerySpec; * @author Christian Beikov */ public class CorrelatedTableGroup extends AbstractTableGroup { - private final TableGroup correlatedTableGroup; private final QuerySpec querySpec; private final Consumer joinPredicateConsumer; public CorrelatedTableGroup( + boolean canUseInnerJoins, TableGroup correlatedTableGroup, SqlAliasBase sqlAliasBase, QuerySpec querySpec, Consumer joinPredicateConsumer, SessionFactoryImplementor sessionFactory) { super( + canUseInnerJoins, correlatedTableGroup.getNavigablePath(), (TableGroupProducer) correlatedTableGroup.getExpressionType(), null, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/LazyTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/LazyTableGroup.java index a2ab927bbf..78abb33a5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/LazyTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/LazyTableGroup.java @@ -22,6 +22,7 @@ import org.hibernate.sql.ast.spi.SqlAliasBase; */ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements TableGroup { + private boolean canUseInnerJoins; private final NavigablePath navigablePath; private final TableGroupProducer producer; private final String sourceAlias; @@ -34,6 +35,7 @@ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements private TableGroup tableGroup; public LazyTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, Supplier tableGroupSupplier, Predicate navigablePathChecker, @@ -42,6 +44,7 @@ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements SqlAliasBase sqlAliasBase, SessionFactoryImplementor sessionFactory, TableGroup parentTableGroup) { + this.canUseInnerJoins = canUseInnerJoins; this.navigablePath = navigablePath; this.producer = tableGroupProducer; this.sourceAlias = sourceAlias; @@ -50,6 +53,7 @@ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements this.navigablePathChecker = navigablePathChecker; this.parentTableGroup = parentTableGroup; this.sessionFactory = sessionFactory; + } public TableGroup getUnderlyingTableGroup() { @@ -112,11 +116,8 @@ public class LazyTableGroup extends AbstractColumnReferenceQualifier implements } @Override - public boolean isOuterJoined() { - if ( tableGroup != null ) { - return parentTableGroup.isOuterJoined() || tableGroup.isOuterJoined(); - } - return parentTableGroup.isOuterJoined(); + public boolean canUseInnerJoins() { + return canUseInnerJoins; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/MutatingTableReferenceGroupWrapper.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/MutatingTableReferenceGroupWrapper.java index 667d7a7b70..7a085b75f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/MutatingTableReferenceGroupWrapper.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/MutatingTableReferenceGroupWrapper.java @@ -10,7 +10,6 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; -import org.hibernate.LockMode; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.query.NavigablePath; @@ -88,7 +87,7 @@ public class MutatingTableReferenceGroupWrapper implements VirtualTableGroup { } @Override - public boolean isOuterJoined() { + public boolean canUseInnerJoins() { return false; } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java index a4d720ab35..998130d6c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java @@ -27,6 +27,7 @@ public interface RootTableGroupProducer extends TableGroupProducer, ModelPartCon * Create a root TableGroup as defined by this producer */ TableGroup createRootTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, String explicitSourceAlias, Supplier> additionalPredicateCollectorAccess, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/StandardTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/StandardTableGroup.java index f124124d4d..48ec4f0fa2 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/StandardTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/StandardTableGroup.java @@ -27,17 +27,20 @@ public class StandardTableGroup extends AbstractTableGroup { private final BiFunction tableReferenceJoinCreator; private final boolean realTableGroup; private final boolean fetched; + private final boolean canUseInnerJoins; private List tableJoins; public StandardTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, TableGroupProducer tableGroupProducer, String sourceAlias, TableReference primaryTableReference, SqlAliasBase sqlAliasBase, SessionFactoryImplementor sessionFactory) { - super( navigablePath, tableGroupProducer, sourceAlias, sqlAliasBase, sessionFactory ); + super( canUseInnerJoins, navigablePath, tableGroupProducer, sourceAlias, sqlAliasBase, sessionFactory ); + this.canUseInnerJoins = canUseInnerJoins; this.primaryTableReference = primaryTableReference; this.realTableGroup = false; this.fetched = false; @@ -54,6 +57,7 @@ public class StandardTableGroup extends AbstractTableGroup { } public StandardTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, TableGroupProducer tableGroupProducer, String sourceAlias, @@ -63,7 +67,8 @@ public class StandardTableGroup extends AbstractTableGroup { Predicate tableReferenceJoinNameChecker, BiFunction tableReferenceJoinCreator, SessionFactoryImplementor sessionFactory) { - super( navigablePath, tableGroupProducer, sourceAlias, sqlAliasBase, sessionFactory ); + super( canUseInnerJoins, navigablePath, tableGroupProducer, sourceAlias, sqlAliasBase, sessionFactory ); + this.canUseInnerJoins = canUseInnerJoins; this.primaryTableReference = primaryTableReference; this.realTableGroup = realTableGroup; this.fetched = false; @@ -73,6 +78,7 @@ public class StandardTableGroup extends AbstractTableGroup { } public StandardTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, TableGroupProducer tableGroupProducer, boolean fetched, @@ -83,7 +89,8 @@ public class StandardTableGroup extends AbstractTableGroup { Predicate tableReferenceJoinNameChecker, BiFunction tableReferenceJoinCreator, SessionFactoryImplementor sessionFactory) { - super( navigablePath, tableGroupProducer, sourceAlias, sqlAliasBase, sessionFactory ); + super( canUseInnerJoins, navigablePath, tableGroupProducer, sourceAlias, sqlAliasBase, sessionFactory ); + this.canUseInnerJoins = canUseInnerJoins; this.primaryTableReference = primaryTableReference; this.realTableGroup = realTableGroup; this.fetched = fetched; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java index a5123b3056..1b9f7c6ff7 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java @@ -7,10 +7,8 @@ package org.hibernate.sql.ast.tree.from; import java.util.List; -import java.util.Set; import java.util.function.Consumer; -import org.hibernate.LockMode; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.sql.internal.DomainResultProducer; @@ -42,7 +40,7 @@ public interface TableGroup extends SqlAstNode, ColumnReferenceQualifier, SqmPat List getTableGroupJoins(); - boolean isOuterJoined(); + boolean canUseInnerJoins(); boolean hasTableGroupJoins(); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableGroup.java index 6f63f0b1e7..0c0d7684d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/UnionTableGroup.java @@ -15,25 +15,26 @@ import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.persister.entity.UnionSubclassEntityPersister; import org.hibernate.query.NavigablePath; -import org.hibernate.sql.ast.SqlAstJoinType; /** * @author Andrea Boriero */ public class UnionTableGroup implements VirtualTableGroup { + private final boolean canUseInnerJoins; private final NavigablePath navigablePath; private List tableGroupJoins; private final UnionSubclassEntityPersister modelPart; private final String sourceAlias; private final TableReference tableReference; - private boolean isOuterJoined; public UnionTableGroup( + boolean canUseInnerJoins, NavigablePath navigablePath, TableReference tableReference, UnionSubclassEntityPersister modelPart, String sourceAlias) { + this.canUseInnerJoins = canUseInnerJoins; this.navigablePath = navigablePath; this.tableReference = tableReference; this.modelPart = modelPart; @@ -76,8 +77,8 @@ public class UnionTableGroup implements VirtualTableGroup { } @Override - public boolean isOuterJoined() { - return isOuterJoined; + public boolean canUseInnerJoins() { + return canUseInnerJoins; } @Override @@ -85,9 +86,6 @@ public class UnionTableGroup implements VirtualTableGroup { if ( tableGroupJoins == null ) { tableGroupJoins = new ArrayList<>(); } - if ( join.getJoinType() != SqlAstJoinType.INNER ) { - isOuterJoined = true; - } if ( !tableGroupJoins.contains( join ) ) { tableGroupJoins.add( join ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EntityCollectionPartTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EntityCollectionPartTableGroup.java index 858c2d1adf..dffb73204b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EntityCollectionPartTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EntityCollectionPartTableGroup.java @@ -66,8 +66,8 @@ public class EntityCollectionPartTableGroup implements TableGroup { } @Override - public boolean isOuterJoined() { - return collectionTableGroup.isOuterJoined(); + public boolean canUseInnerJoins() { + return collectionTableGroup.canUseInnerJoins(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java index c79ab22a5f..8a76c4b904 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java @@ -13,6 +13,7 @@ import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.query.NavigablePath; import org.hibernate.sql.ast.SqlAstJoinType; import org.hibernate.sql.ast.spi.FromClauseAccess; +import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.results.graph.AbstractFetchParent; import org.hibernate.sql.results.graph.AssemblerCreationState; @@ -46,9 +47,10 @@ public class EmbeddableResultImpl extends AbstractFetchParent implements Embe navigablePath, np -> { final EmbeddableValuedModelPart embeddedValueMapping = modelPart.getEmbeddableTypeDescriptor().getEmbeddedValueMapping(); + final TableGroup tableGroup = fromClauseAccess.findTableGroup( navigablePath.getParent() ); final TableGroupJoin tableGroupJoin = embeddedValueMapping.createTableGroupJoin( navigablePath, - fromClauseAccess.findTableGroup( navigablePath.getParent() ), + tableGroup, resultVariable, SqlAstJoinType.INNER, true,