Do not eagerly create a table group for implicit joins
This commit is contained in:
parent
3df3d37dbd
commit
9a22e615f5
|
@ -129,18 +129,25 @@ public abstract class AbstractCompositeIdentifierMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
|
@ -149,7 +156,7 @@ public abstract class AbstractCompositeIdentifierMapping
|
|||
creationContext
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, SqlAstJoinType.LEFT, tableGroup, null );
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,7 +164,7 @@ public abstract class AbstractCompositeIdentifierMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
|
|
|
@ -105,14 +105,12 @@ public interface ForeignKeyDescriptor extends VirtualModelPart, ValueMapping {
|
|||
Predicate generateJoinPredicate(
|
||||
TableGroup targetSideTableGroup,
|
||||
TableGroup keySideTableGroup,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext);
|
||||
|
||||
Predicate generateJoinPredicate(
|
||||
TableReference targetSideReference,
|
||||
TableReference keySideReference,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext);
|
||||
|
||||
|
|
|
@ -381,18 +381,25 @@ public class DiscriminatedAssociationAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
|
@ -401,7 +408,7 @@ public class DiscriminatedAssociationAttributeMapping
|
|||
creationContext
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, sqlAstJoinType, tableGroup );
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -409,7 +416,7 @@ public class DiscriminatedAssociationAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
|
|
|
@ -245,18 +245,25 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
|
@ -265,7 +272,7 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode
|
|||
creationContext
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, sqlAstJoinType, tableGroup );
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -273,7 +280,7 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
|
|
|
@ -295,18 +295,25 @@ public class EmbeddedAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
|
@ -315,7 +322,7 @@ public class EmbeddedAttributeMapping
|
|||
creationContext
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, sqlAstJoinType, tableGroup );
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -323,7 +330,7 @@ public class EmbeddedAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
|
|
|
@ -224,18 +224,25 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
|
@ -244,7 +251,7 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
|||
creationContext
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, sqlAstJoinType, tableGroup, null );
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -252,7 +259,7 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
|
|
|
@ -369,7 +369,6 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
public Predicate generateJoinPredicate(
|
||||
TableGroup targetSideTableGroup,
|
||||
TableGroup keySideTableGroup,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final TableReference lhsTableReference = targetSideTableGroup.resolveTableReference(
|
||||
|
@ -381,7 +380,6 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
return generateJoinPredicate(
|
||||
lhsTableReference,
|
||||
rhsTableKeyReference,
|
||||
sqlAstJoinType,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
);
|
||||
|
@ -391,7 +389,6 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
public Predicate generateJoinPredicate(
|
||||
TableReference targetSideReference,
|
||||
TableReference keySideReference,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return getPredicate( targetSideReference, keySideReference, creationContext, targetSelectableMappings, keySelectableMappings );
|
||||
|
|
|
@ -557,18 +557,25 @@ public class EntityCollectionPart
|
|||
NavigablePath navigablePath,
|
||||
TableGroup collectionTableGroup,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
if ( collectionDescriptor.isOneToMany() && nature == Nature.ELEMENT ) {
|
||||
// If this is a one-to-many, the element part is already available, so we return a TableGroupJoin "hull"
|
||||
return new TableGroupJoin(
|
||||
navigablePath,
|
||||
sqlAstJoinType,
|
||||
joinType,
|
||||
( (OneToManyTableGroup) collectionTableGroup ).getElementTableGroup(),
|
||||
null
|
||||
);
|
||||
|
@ -578,7 +585,7 @@ public class EntityCollectionPart
|
|||
navigablePath,
|
||||
collectionTableGroup,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
|
@ -588,7 +595,7 @@ public class EntityCollectionPart
|
|||
);
|
||||
final TableGroupJoin join = new TableGroupJoin(
|
||||
navigablePath,
|
||||
sqlAstJoinType,
|
||||
joinType,
|
||||
lazyTableGroup,
|
||||
null
|
||||
);
|
||||
|
@ -598,7 +605,6 @@ public class EntityCollectionPart
|
|||
fkDescriptor.generateJoinPredicate(
|
||||
tableGroup.getPrimaryTableReference(),
|
||||
collectionTableGroup.resolveTableReference( fkDescriptor.getKeyTable() ),
|
||||
sqlAstJoinType,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
)
|
||||
|
@ -613,15 +619,22 @@ public class EntityCollectionPart
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final SqlAliasBase sqlAliasBase = aliasBaseGenerator.createSqlAliasBase( getSqlAliasStem() );
|
||||
final boolean canUseInnerJoin = sqlAstJoinType == SqlAstJoinType.INNER || lhs.canUseInnerJoins();
|
||||
final boolean canUseInnerJoin = joinType == SqlAstJoinType.INNER || lhs.canUseInnerJoins();
|
||||
final LazyTableGroup lazyTableGroup = new LazyTableGroup(
|
||||
canUseInnerJoin,
|
||||
navigablePath,
|
||||
|
@ -671,7 +684,6 @@ public class EntityCollectionPart
|
|||
fkDescriptor.generateJoinPredicate(
|
||||
tableGroup.getPrimaryTableReference(),
|
||||
keySideTableReference,
|
||||
sqlAstJoinType,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
)
|
||||
|
|
|
@ -527,19 +527,26 @@ public class PluralAttributeMappingImpl
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final java.util.List<Predicate> predicates = new ArrayList<>( 2 );
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
predicates::add,
|
||||
aliasBaseGenerator,
|
||||
|
@ -549,7 +556,7 @@ public class PluralAttributeMappingImpl
|
|||
);
|
||||
final TableGroupJoin tableGroupJoin = new TableGroupJoin(
|
||||
navigablePath,
|
||||
sqlAstJoinType,
|
||||
joinType,
|
||||
tableGroup,
|
||||
null
|
||||
);
|
||||
|
@ -562,18 +569,25 @@ public class PluralAttributeMappingImpl
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final CollectionPersister collectionDescriptor = getCollectionDescriptor();
|
||||
final TableGroup tableGroup;
|
||||
if ( collectionDescriptor.isOneToMany() ) {
|
||||
tableGroup = createOneToManyTableGroup(
|
||||
lhs.canUseInnerJoins() && sqlAstJoinType == SqlAstJoinType.INNER,
|
||||
lhs.canUseInnerJoins() && joinType == SqlAstJoinType.INNER,
|
||||
navigablePath,
|
||||
fetched,
|
||||
explicitSourceAlias,
|
||||
|
@ -585,7 +599,7 @@ public class PluralAttributeMappingImpl
|
|||
}
|
||||
else {
|
||||
tableGroup = createCollectionTableGroup(
|
||||
lhs.canUseInnerJoins() && sqlAstJoinType == SqlAstJoinType.INNER,
|
||||
lhs.canUseInnerJoins() && joinType == SqlAstJoinType.INNER,
|
||||
navigablePath,
|
||||
fetched,
|
||||
explicitSourceAlias,
|
||||
|
@ -601,7 +615,6 @@ public class PluralAttributeMappingImpl
|
|||
getKeyDescriptor().generateJoinPredicate(
|
||||
lhs,
|
||||
tableGroup,
|
||||
sqlAstJoinType,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
)
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
import org.hibernate.query.sqm.ComparisonOperator;
|
||||
import org.hibernate.query.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.Clause;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
|
@ -266,7 +265,6 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
|||
public Predicate generateJoinPredicate(
|
||||
TableReference targetSideReference,
|
||||
TableReference keySideReference,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return new ComparisonPredicate(
|
||||
|
@ -288,7 +286,6 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
|||
public Predicate generateJoinPredicate(
|
||||
TableGroup targetSideTableGroup,
|
||||
TableGroup keySideTableGroup,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final TableReference lhsTableReference = targetSideTableGroup.resolveTableReference(
|
||||
|
@ -302,7 +299,6 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
|||
return generateJoinPredicate(
|
||||
lhsTableReference,
|
||||
rhsTableKeyReference,
|
||||
sqlAstJoinType,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
);
|
||||
|
|
|
@ -1245,7 +1245,7 @@ public class ToOneAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
|
@ -1273,10 +1273,17 @@ public class ToOneAttributeMapping
|
|||
break;
|
||||
}
|
||||
}
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
// If a parent is a collection part, there is no custom predicate and the join is INNER or LEFT
|
||||
// we check if this attribute is the map key property to reuse the existing index table group
|
||||
if ( CollectionPart.Nature.ELEMENT.getName().equals( parentTableGroup.getNavigablePath().getUnaliasedLocalName() )
|
||||
&& !addsPredicate && ( sqlAstJoinType == SqlAstJoinType.INNER || sqlAstJoinType == SqlAstJoinType.LEFT ) ) {
|
||||
&& !addsPredicate && ( joinType == SqlAstJoinType.INNER || joinType == SqlAstJoinType.LEFT ) ) {
|
||||
final PluralTableGroup pluralTableGroup = (PluralTableGroup) fromClauseAccess.findTableGroup(
|
||||
parentTableGroup.getNavigablePath().getParent()
|
||||
);
|
||||
|
@ -1293,10 +1300,10 @@ public class ToOneAttributeMapping
|
|||
if ( pathName.equals( indexPropertyName ) ) {
|
||||
final TableGroup indexTableGroup = pluralTableGroup.getIndexTableGroup();
|
||||
// If this is the map key property, we can reuse the index table group
|
||||
initializeIfNeeded( lhs, sqlAstJoinType, indexTableGroup );
|
||||
initializeIfNeeded( lhs, requestedJoinType, indexTableGroup );
|
||||
return new TableGroupJoin(
|
||||
navigablePath,
|
||||
sqlAstJoinType,
|
||||
joinType,
|
||||
new MappedByTableGroup(
|
||||
navigablePath,
|
||||
this,
|
||||
|
@ -1333,7 +1340,7 @@ public class ToOneAttributeMapping
|
|||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
|
@ -1343,7 +1350,7 @@ public class ToOneAttributeMapping
|
|||
);
|
||||
final TableGroupJoin join = new TableGroupJoin(
|
||||
navigablePath,
|
||||
sqlAstJoinType,
|
||||
joinType,
|
||||
lazyTableGroup,
|
||||
null
|
||||
);
|
||||
|
@ -1355,7 +1362,6 @@ public class ToOneAttributeMapping
|
|||
foreignKeyDescriptor.generateJoinPredicate(
|
||||
sideNature == ForeignKeyDescriptor.Nature.TARGET ? lhsTableReference : tableGroup.getPrimaryTableReference(),
|
||||
sideNature == ForeignKeyDescriptor.Nature.TARGET ? tableGroup.getPrimaryTableReference() : lhsTableReference,
|
||||
sqlAstJoinType,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
)
|
||||
|
@ -1370,7 +1376,7 @@ public class ToOneAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
|
@ -1378,7 +1384,14 @@ public class ToOneAttributeMapping
|
|||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAliasBase sqlAliasBase = aliasBaseGenerator.createSqlAliasBase( sqlAliasStem );
|
||||
final boolean canUseInnerJoin = sqlAstJoinType == SqlAstJoinType.INNER || lhs.canUseInnerJoins() && !isNullable;
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
joinType = requestedJoinType;
|
||||
}
|
||||
final boolean canUseInnerJoin = joinType == SqlAstJoinType.INNER || lhs.canUseInnerJoins() && !isNullable;
|
||||
|
||||
TableGroup realParentTableGroup = lhs;
|
||||
while ( realParentTableGroup.getModelPart() instanceof EmbeddableValuedModelPart ) {
|
||||
|
@ -1446,7 +1459,6 @@ public class ToOneAttributeMapping
|
|||
foreignKeyDescriptor.generateJoinPredicate(
|
||||
sideNature == ForeignKeyDescriptor.Nature.TARGET ? lhsTableReference : tableGroup.getPrimaryTableReference(),
|
||||
sideNature == ForeignKeyDescriptor.Nature.TARGET ? tableGroup.getPrimaryTableReference() : lhsTableReference,
|
||||
sqlAstJoinType,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
)
|
||||
|
@ -1459,7 +1471,7 @@ public class ToOneAttributeMapping
|
|||
lazyTableGroup.getPrimaryTableReference();
|
||||
}
|
||||
else {
|
||||
initializeIfNeeded( lhs, sqlAstJoinType, lazyTableGroup );
|
||||
initializeIfNeeded( lhs, requestedJoinType, lazyTableGroup );
|
||||
}
|
||||
|
||||
return lazyTableGroup;
|
||||
|
|
|
@ -245,7 +245,6 @@ import org.hibernate.query.sqm.tree.update.SqmSetClause;
|
|||
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
|
||||
import org.hibernate.sql.ast.Clause;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.SqlTreeCreationException;
|
||||
import org.hibernate.sql.ast.SqlTreeCreationLogger;
|
||||
import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
|
@ -2735,14 +2734,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
implicitJoinChecker = BaseSqmToSqlAstConverter::verifyManipulationImplicitJoin;
|
||||
}
|
||||
final FromClauseIndex fromClauseIndex = fromClauseIndexStack.getCurrent();
|
||||
prepareReusablePath( fromClauseIndex, sqmPath, false, implicitJoinChecker );
|
||||
prepareReusablePath( fromClauseIndex, sqmPath, implicitJoinChecker );
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
private TableGroup prepareReusablePath(
|
||||
FromClauseIndex fromClauseIndex,
|
||||
JpaPath<?> sqmPath,
|
||||
boolean useInnerJoin,
|
||||
Consumer<TableGroup> implicitJoinChecker) {
|
||||
final JpaPath<?> parentPath;
|
||||
if ( sqmPath instanceof SqmTreatedPath<?, ?> ) {
|
||||
|
@ -2759,14 +2757,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
final TableGroup parentTableGroup = prepareReusablePath(
|
||||
fromClauseIndex,
|
||||
parentPath,
|
||||
useInnerJoin,
|
||||
implicitJoinChecker
|
||||
);
|
||||
if ( parentPath instanceof SqmTreatedPath<?, ?> ) {
|
||||
fromClauseIndex.register( (SqmPath<?>) parentPath, parentTableGroup );
|
||||
return parentTableGroup;
|
||||
}
|
||||
final TableGroup newTableGroup = createTableGroup( parentTableGroup, (SqmPath<?>) parentPath, useInnerJoin );
|
||||
final TableGroup newTableGroup = createTableGroup( parentTableGroup, (SqmPath<?>) parentPath );
|
||||
if ( newTableGroup != null ) {
|
||||
implicitJoinChecker.accept( newTableGroup );
|
||||
if ( sqmPath instanceof SqmFrom<?, ?> ) {
|
||||
|
@ -2803,14 +2800,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
else {
|
||||
navigablePath = joinedPath.getLhs().getNavigablePath();
|
||||
}
|
||||
// todo (6.0): check again if this really is a "requirement" by the JPA spec and document the reference if it is.
|
||||
// The additional join will filter rows, so there would be no way to just select the FK for a nullable association
|
||||
final boolean useInnerJoin = true;
|
||||
// INNER join semantics are required per the JPA spec for select items.
|
||||
final TableGroup createdTableGroup = createTableGroup(
|
||||
fromClauseIndex.getTableGroup( navigablePath ),
|
||||
joinedPath,
|
||||
useInnerJoin
|
||||
joinedPath
|
||||
);
|
||||
if ( createdTableGroup != null && joinedPath instanceof SqmTreatedPath<?, ?> ) {
|
||||
fromClauseIndex.register( joinedPath, createdTableGroup );
|
||||
|
@ -2821,7 +2813,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
}
|
||||
}
|
||||
|
||||
private TableGroup createTableGroup(TableGroup parentTableGroup, SqmPath<?> joinedPath, boolean useInnerJoin) {
|
||||
private TableGroup createTableGroup(TableGroup parentTableGroup, SqmPath<?> joinedPath) {
|
||||
final TableGroup actualParentTableGroup = findActualTableGroup( parentTableGroup, joinedPath );
|
||||
final SqmPath<?> lhsPath = joinedPath.getLhs();
|
||||
final FromClauseIndex fromClauseIndex = getFromClauseIndex();
|
||||
|
@ -2837,15 +2829,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
final TableGroupJoinProducer joinProducer = (TableGroupJoinProducer) subPart;
|
||||
final SqlAstJoinType defaultSqlAstJoinType;
|
||||
|
||||
// The check for joinProducer being an instance of PluralAttributeMapping is necessary
|
||||
// for cases where we are consuming a reusable path for special case in which de-referencing a plural path is allowed,
|
||||
// i.e.`select key(s.addresses) from Student s`.
|
||||
if ( useInnerJoin || joinProducer instanceof PluralAttributeMapping ) {
|
||||
defaultSqlAstJoinType = SqlAstJoinType.INNER;
|
||||
}
|
||||
else {
|
||||
defaultSqlAstJoinType = joinProducer.getDefaultSqlAstJoinType( actualParentTableGroup );
|
||||
}
|
||||
if ( fromClauseIndex.findTableGroupOnLeaf( actualParentTableGroup.getNavigablePath() ) == null ) {
|
||||
final QuerySpec querySpec = currentQuerySpec();
|
||||
// The parent table group is on a parent query, so we need a root table group
|
||||
|
@ -2853,7 +2836,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
joinedPath.getNavigablePath(),
|
||||
actualParentTableGroup,
|
||||
null,
|
||||
defaultSqlAstJoinType,
|
||||
null,
|
||||
false,
|
||||
querySpec::applyPredicate,
|
||||
this
|
||||
|
@ -2867,14 +2850,14 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
final TableGroup compatibleTableGroup = findCompatibleJoinedGroup(
|
||||
actualParentTableGroup,
|
||||
joinProducer,
|
||||
defaultSqlAstJoinType
|
||||
SqlAstJoinType.INNER
|
||||
);
|
||||
if ( compatibleTableGroup == null ) {
|
||||
final TableGroupJoin tableGroupJoin = joinProducer.createTableGroupJoin(
|
||||
joinedPath.getNavigablePath(),
|
||||
actualParentTableGroup,
|
||||
null,
|
||||
defaultSqlAstJoinType,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
this
|
||||
|
@ -3436,7 +3419,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(
|
||||
parentTableGroup,
|
||||
tableGroup,
|
||||
SqlAstJoinType.INNER,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
)
|
||||
|
@ -3619,7 +3601,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(
|
||||
parentFromClauseAccess.findTableGroup( parent ),
|
||||
tableGroup,
|
||||
SqlAstJoinType.INNER,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
)
|
||||
|
@ -3752,7 +3733,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralPartPath.getPluralDomainPath().getNavigablePath().getParent()
|
||||
),
|
||||
tableGroup,
|
||||
SqlAstJoinType.INNER,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
)
|
||||
|
@ -5435,7 +5415,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(
|
||||
parentFromClauseAccess.findTableGroup( pluralPath.getNavigablePath().getParent() ),
|
||||
tableGroup,
|
||||
SqlAstJoinType.INNER,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
)
|
||||
|
|
|
@ -28,6 +28,8 @@ public interface TableGroupJoinProducer extends TableGroupProducer {
|
|||
|
||||
/**
|
||||
* Create a TableGroupJoin as defined for this producer
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
*/
|
||||
default TableGroupJoin createTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
|
@ -53,6 +55,8 @@ public interface TableGroupJoinProducer extends TableGroupProducer {
|
|||
|
||||
/**
|
||||
* Create a TableGroupJoin as defined for this producer
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
*/
|
||||
TableGroupJoin createTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
|
@ -68,6 +72,8 @@ public interface TableGroupJoinProducer extends TableGroupProducer {
|
|||
|
||||
/**
|
||||
* Create a TableGroup as defined for this producer
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
*/
|
||||
default TableGroup createRootTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
|
@ -93,6 +99,8 @@ public interface TableGroupJoinProducer extends TableGroupProducer {
|
|||
|
||||
/**
|
||||
* Create a TableGroupJoin as defined for this producer
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
*/
|
||||
TableGroup createRootTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
|
|
Loading…
Reference in New Issue