Fix wrong creation of inner join

This commit is contained in:
Andrea Boriero 2021-07-06 16:22:17 +02:00
parent ba5f77210a
commit 241300c0c1
36 changed files with 110 additions and 55 deletions

View File

@ -50,6 +50,7 @@ public class InformixSqmToSqlAstConverter<T extends Statement> extends BaseSqmTo
if ( this.needsDummyTableGroup ) {
querySpec.getFromClause().addRoot(
new StandardTableGroup(
false,
null,
null,
null,

View File

@ -50,6 +50,7 @@ public class IngresSqmToSqlAstConverter<T extends Statement> extends BaseSqmToSq
if ( this.needsDummyTableGroup ) {
querySpec.getFromClause().addRoot(
new StandardTableGroup(
false,
null,
null,
null,

View File

@ -50,6 +50,7 @@ public class SybaseSqmToSqlAstConverter<T extends Statement> extends BaseSqmToSq
if ( this.needsDummyTableGroup ) {
querySpec.getFromClause().addRoot(
new StandardTableGroup(
true,
null,
null,
null,

View File

@ -177,6 +177,7 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
);
final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup(
true,
entityPath,
null,
() -> rootQuerySpec::applyPredicate,

View File

@ -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,

View File

@ -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,

View File

@ -37,6 +37,7 @@ public interface Loadable extends ModelPart, RootTableGroupProducer {
@Override
default TableGroup createRootTableGroup(
boolean canUseInnerJoins,
NavigablePath navigablePath,
String explicitSourceAlias,
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,

View File

@ -41,6 +41,7 @@ public interface EntityAssociationMapping extends ModelPart, Association, TableG
* Create a delayed DomainResult for a specific reference to this ModelPart.
*/
default <T> DomainResult<T> createDelayedDomainResult(
boolean canUseInnerJoins,
NavigablePath navigablePath,
TableGroup tableGroup,
String resultVariable,

View File

@ -276,12 +276,14 @@ public interface EntityMappingType extends ManagedMappingType, EntityValuedModel
@Override
default TableGroup createRootTableGroup(
boolean canUseInnerJoins,
NavigablePath navigablePath,
String explicitSourceAlias,
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
SqlAstCreationState creationState,
SqlAstCreationContext creationContext) {
return getEntityPersister().createRootTableGroup(
canUseInnerJoins,
navigablePath,
explicitSourceAlias,
additionalPredicateCollectorAccess,

View File

@ -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<Consumer<Predicate>> 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,

View File

@ -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;

View File

@ -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 <T> DomainResult<T> 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,

View File

@ -1367,6 +1367,7 @@ public abstract class AbstractEntityPersister
@Override
public TableGroup createRootTableGroup(
boolean canUseInnerJoins,
NavigablePath navigablePath,
String explicitSourceAlias,
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
@ -1383,6 +1384,7 @@ public abstract class AbstractEntityPersister
);
return new StandardTableGroup(
canUseInnerJoins,
navigablePath,
this,
explicitSourceAlias,

View File

@ -927,12 +927,14 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
@Override
public TableGroup createRootTableGroup(
boolean canUseInnerJoins,
NavigablePath navigablePath,
String explicitSourceAlias,
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
SqlAstCreationState creationState,
SqlAstCreationContext creationContext) {
final TableGroup tableGroup = super.createRootTableGroup(
canUseInnerJoins,
navigablePath,
explicitSourceAlias,
additionalPredicateCollectorAccess,

View File

@ -241,6 +241,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
@Override
public TableGroup createRootTableGroup(
boolean canUseInnerJoins,
NavigablePath navigablePath,
String explicitSourceAlias,
Supplier<Consumer<Predicate>> 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

View File

@ -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 );
}

View File

@ -79,6 +79,7 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti
impl.getFromClauseAccess().resolveTableGroup(
navigablePath,
np -> entityDescriptor.createRootTableGroup(
true,
navigablePath,
null,
() -> predicate -> {},

View File

@ -71,6 +71,7 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde
impl.getFromClauseAccess().resolveTableGroup(
navigablePath,
np -> entityDescriptor.createRootTableGroup(
true,
navigablePath,
null,
() -> predicate -> {},

View File

@ -57,6 +57,7 @@ public class ImplicitModelPartResultBuilderEntity
}
return modelPart.getEntityMappingType().createRootTableGroup(
true,
navigablePath,
null,
() -> predicate -> {

View File

@ -103,6 +103,7 @@ public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter<Sta
final NavigablePath navigablePath = new NavigablePath( mutatingEntityDescriptor.getEntityName(), mutatingEntityExplicitAlias );
this.mutatingTableGroup = mutatingEntityDescriptor.createRootTableGroup(
true,
navigablePath,
sourceAlias,
() -> predicate -> {

View File

@ -173,6 +173,7 @@ public final class ExecuteWithIdTableHelper {
executionContext.getSession().getFactory()
);
final TableGroup idTableGroup = new StandardTableGroup(
true,
new NavigablePath( idTableReference.getTableExpression() ),
entityDescriptor,
null,

View File

@ -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(),

View File

@ -593,6 +593,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> extends Base
);
try {
final TableGroup tableGroup = collectionPart.createRootTableGroup(
true,
pluralPath.getNavigablePath(),
null,
() -> subQuerySpec::applyPredicate,
@ -4017,6 +4027,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
);
try {
final TableGroup tableGroup = mappingModelExpressable.createRootTableGroup(
true,
pluralPartPath.getNavigablePath(),
null,
() -> subQuerySpec::applyPredicate,
@ -4165,6 +4176,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
);
try {
final TableGroup tableGroup = mappingModelExpressable.createRootTableGroup(
true,
pluralPath.getNavigablePath(),
null,
() -> subQuerySpec::applyPredicate,
@ -4269,6 +4281,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> 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,

View File

@ -78,6 +78,7 @@ public class CteTable {
);
final StandardTableGroup tableValueCtorGroup = new StandardTableGroup(
true,
new NavigablePath( "cte" ),
null,
null,

View File

@ -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;
}

View File

@ -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<TableGroupJoin> 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 );
}

View File

@ -25,12 +25,13 @@ public class CompositeTableGroup implements VirtualTableGroup {
private final TableGroup underlyingTableGroup;
private List<TableGroupJoin> 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 );
}

View File

@ -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<Predicate> joinPredicateConsumer;
public CorrelatedTableGroup(
boolean canUseInnerJoins,
TableGroup correlatedTableGroup,
SqlAliasBase sqlAliasBase,
QuerySpec querySpec,
Consumer<Predicate> joinPredicateConsumer,
SessionFactoryImplementor sessionFactory) {
super(
canUseInnerJoins,
correlatedTableGroup.getNavigablePath(),
(TableGroupProducer) correlatedTableGroup.getExpressionType(),
null,

View File

@ -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<TableGroup> tableGroupSupplier,
Predicate<NavigablePath> 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

View File

@ -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;
}

View File

@ -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<Consumer<Predicate>> additionalPredicateCollectorAccess,

View File

@ -27,17 +27,20 @@ public class StandardTableGroup extends AbstractTableGroup {
private final BiFunction<String,TableGroup,TableReferenceJoin> tableReferenceJoinCreator;
private final boolean realTableGroup;
private final boolean fetched;
private final boolean canUseInnerJoins;
private List<TableReferenceJoin> 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<String> tableReferenceJoinNameChecker,
BiFunction<String, TableGroup, TableReferenceJoin> 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<String> tableReferenceJoinNameChecker,
BiFunction<String, TableGroup, TableReferenceJoin> 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;

View File

@ -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<TableGroupJoin> getTableGroupJoins();
boolean isOuterJoined();
boolean canUseInnerJoins();
boolean hasTableGroupJoins();

View File

@ -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<TableGroupJoin> 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 );
}

View File

@ -66,8 +66,8 @@ public class EntityCollectionPartTableGroup implements TableGroup {
}
@Override
public boolean isOuterJoined() {
return collectionTableGroup.isOuterJoined();
public boolean canUseInnerJoins() {
return collectionTableGroup.canUseInnerJoins();
}
@Override

View File

@ -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<T> 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,