HHH-16198 - Fix splitting of SqlAstCreationState
This commit is contained in:
parent
e509625af8
commit
7b58a33520
|
@ -162,9 +162,9 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
|
|||
true,
|
||||
entityPath,
|
||||
null,
|
||||
null,
|
||||
() -> rootQuerySpec::applyPredicate,
|
||||
sqlAstCreationState,
|
||||
sessionFactory
|
||||
sqlAstCreationState
|
||||
);
|
||||
|
||||
rootQuerySpec.getFromClause().addRoot( rootTableGroup );
|
||||
|
|
|
@ -84,9 +84,9 @@ class DatabaseSnapshotExecutor {
|
|||
true,
|
||||
rootPath,
|
||||
null,
|
||||
null,
|
||||
() -> rootQuerySpec::applyPredicate,
|
||||
state,
|
||||
sessionFactory
|
||||
state
|
||||
);
|
||||
|
||||
rootQuerySpec.getFromClause().addRoot( rootTableGroup );
|
||||
|
|
|
@ -386,9 +386,9 @@ public class LoaderSelectBuilder {
|
|||
true,
|
||||
rootNavigablePath,
|
||||
null,
|
||||
null,
|
||||
() -> rootQuerySpec::applyPredicate,
|
||||
sqlAstCreationState,
|
||||
creationContext
|
||||
sqlAstCreationState
|
||||
);
|
||||
|
||||
rootQuerySpec.getFromClause().addRoot( rootTableGroup );
|
||||
|
@ -406,6 +406,7 @@ public class LoaderSelectBuilder {
|
|||
navigablePath,
|
||||
rootTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.LEFT,
|
||||
true,
|
||||
false,
|
||||
|
@ -966,9 +967,9 @@ public class LoaderSelectBuilder {
|
|||
true,
|
||||
rootNavigablePath,
|
||||
null,
|
||||
null,
|
||||
() -> rootQuerySpec::applyPredicate,
|
||||
sqlAstCreationState,
|
||||
creationContext
|
||||
sqlAstCreationState
|
||||
);
|
||||
|
||||
rootQuerySpec.getFromClause().addRoot( rootTableGroup );
|
||||
|
|
|
@ -16,24 +16,21 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
|||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
||||
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
import org.hibernate.metamodel.mapping.SelectableMappings;
|
||||
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
|
||||
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.Clause;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||
|
@ -129,13 +126,11 @@ public abstract class AbstractCompositeIdentifierMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
|
@ -147,13 +142,11 @@ public abstract class AbstractCompositeIdentifierMapping
|
|||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup, null );
|
||||
|
@ -164,13 +157,11 @@ public abstract class AbstractCompositeIdentifierMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
return new StandardVirtualTableGroup( navigablePath, this, lhs, fetched );
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,8 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
|
||||
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||
import org.hibernate.sql.ast.tree.from.TableReferenceJoin;
|
||||
|
@ -508,47 +505,22 @@ public interface EntityMappingType
|
|||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAstCreationState creationState,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return createRootTableGroup(
|
||||
canUseInnerJoins,
|
||||
navigablePath,
|
||||
explicitSourceAlias,
|
||||
additionalPredicateCollectorAccess,
|
||||
creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() ),
|
||||
creationState.getSqlExpressionResolver(),
|
||||
creationState.getFromClauseAccess(),
|
||||
creationContext
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
default TableGroup createRootTableGroup(
|
||||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver expressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
return getEntityPersister().createRootTableGroup(
|
||||
canUseInnerJoins,
|
||||
navigablePath,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
additionalPredicateCollectorAccess,
|
||||
sqlAliasBase,
|
||||
expressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
}
|
||||
|
||||
default TableReference createPrimaryTableReference(
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
throw new UnsupportedMappingException(
|
||||
"Entity mapping does not support primary TableReference creation [" +
|
||||
getClass().getName() + " : " + getEntityName() + "]"
|
||||
|
@ -559,8 +531,7 @@ public interface EntityMappingType
|
|||
String joinTableExpression,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
TableReference lhs,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
throw new UnsupportedMappingException(
|
||||
"Entity mapping does not support primary TableReference join creation [" +
|
||||
getClass().getName() + " : " + getEntityName() + "]"
|
||||
|
|
|
@ -11,8 +11,7 @@ import java.util.function.IntFunction;
|
|||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupProducer;
|
||||
import org.hibernate.sql.ast.tree.from.TableReference;
|
||||
|
@ -81,7 +80,8 @@ public interface ForeignKeyDescriptor extends VirtualModelPart, ValuedModelPart
|
|||
DomainResult<?> createKeyDomainResult(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup tableGroup,
|
||||
FetchParent fetchParent, DomainResultCreationState creationState);
|
||||
FetchParent fetchParent,
|
||||
DomainResultCreationState creationState);
|
||||
|
||||
/**
|
||||
* Create a DomainResult for the target-side of the fk
|
||||
|
@ -89,25 +89,25 @@ public interface ForeignKeyDescriptor extends VirtualModelPart, ValuedModelPart
|
|||
DomainResult<?> createTargetDomainResult(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup tableGroup,
|
||||
FetchParent fetchParent, DomainResultCreationState creationState);
|
||||
FetchParent fetchParent,
|
||||
DomainResultCreationState creationState);
|
||||
|
||||
DomainResult<?> createDomainResult(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup tableGroup,
|
||||
Nature side,
|
||||
FetchParent fetchParent, DomainResultCreationState creationState);
|
||||
FetchParent fetchParent,
|
||||
DomainResultCreationState creationState);
|
||||
|
||||
Predicate generateJoinPredicate(
|
||||
TableGroup targetSideTableGroup,
|
||||
TableGroup keySideTableGroup,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationState creationState);
|
||||
|
||||
Predicate generateJoinPredicate(
|
||||
TableReference targetSideReference,
|
||||
TableReference keySideReference,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationState creationState);
|
||||
|
||||
boolean isSimpleJoinPredicate(Predicate predicate);
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.hibernate.spi.NavigablePath;
|
|||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.tree.from.PluralTableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.StandardTableGroup;
|
||||
|
@ -254,12 +255,12 @@ public abstract class AbstractEntityCollectionPart implements EntityCollectionPa
|
|||
boolean fetched,
|
||||
String sourceAlias,
|
||||
final SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstCreationContext creationContext = creationState.getCreationContext();
|
||||
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlExpressionResolver();
|
||||
final TableReference primaryTableReference = getEntityMappingType().createPrimaryTableReference(
|
||||
sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new StandardTableGroup(
|
||||
|
@ -276,8 +277,7 @@ public abstract class AbstractEntityCollectionPart implements EntityCollectionPa
|
|||
tableExpression,
|
||||
sqlAliasBase,
|
||||
primaryTableReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
),
|
||||
creationContext.getSessionFactory()
|
||||
);
|
||||
|
|
|
@ -34,10 +34,8 @@ import org.hibernate.metamodel.model.domain.NavigableRole;
|
|||
import org.hibernate.property.access.spi.PropertyAccess;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.from.StandardVirtualTableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
|
@ -443,25 +441,21 @@ public class DiscriminatedAssociationAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType = Objects.requireNonNullElse( requestedJoinType, SqlAstJoinType.INNER );
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup );
|
||||
|
@ -472,19 +466,12 @@ public class DiscriminatedAssociationAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return new StandardVirtualTableGroup(
|
||||
navigablePath,
|
||||
this,
|
||||
lhs,
|
||||
fetched
|
||||
);
|
||||
SqlAstCreationState creationState) {
|
||||
return new StandardVirtualTableGroup( navigablePath, this, lhs, fetched );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,10 +26,8 @@ import org.hibernate.metamodel.model.domain.NavigableRole;
|
|||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.from.StandardVirtualTableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
|
@ -317,13 +315,11 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
|
@ -335,13 +331,11 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode
|
|||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup );
|
||||
|
@ -352,19 +346,12 @@ public class DiscriminatedCollectionPart implements DiscriminatedAssociationMode
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return new StandardVirtualTableGroup(
|
||||
navigablePath,
|
||||
this,
|
||||
lhs,
|
||||
fetched
|
||||
);
|
||||
SqlAstCreationState creationState) {
|
||||
return new StandardVirtualTableGroup( navigablePath, this, lhs, fetched );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,11 +34,8 @@ import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
|
|||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.Clause;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
|
@ -55,10 +52,10 @@ import org.hibernate.sql.results.graph.Fetch;
|
|||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
import org.hibernate.sql.results.graph.Fetchable;
|
||||
import org.hibernate.sql.results.graph.embeddable.EmbeddableValuedFetchable;
|
||||
import org.hibernate.sql.results.graph.embeddable.internal.AggregateEmbeddableFetchImpl;
|
||||
import org.hibernate.sql.results.graph.embeddable.internal.AggregateEmbeddableResultImpl;
|
||||
import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl;
|
||||
import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableResultImpl;
|
||||
import org.hibernate.sql.results.graph.embeddable.internal.AggregateEmbeddableFetchImpl;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -365,25 +362,21 @@ public class EmbeddedAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType = requestedJoinType == null ? SqlAstJoinType.INNER : requestedJoinType;
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup );
|
||||
|
@ -394,19 +387,12 @@ public class EmbeddedAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return new StandardVirtualTableGroup(
|
||||
navigablePath,
|
||||
this,
|
||||
lhs,
|
||||
fetched
|
||||
);
|
||||
SqlAstCreationState creationState) {
|
||||
return new StandardVirtualTableGroup( navigablePath, this, lhs, fetched );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,8 +31,7 @@ import org.hibernate.spi.NavigablePath;
|
|||
import org.hibernate.sql.ast.Clause;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
|
@ -226,13 +225,11 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
joinType = SqlAstJoinType.INNER;
|
||||
|
@ -244,13 +241,11 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
|||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup, null );
|
||||
|
@ -261,15 +256,12 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
assert lhs.getModelPart() instanceof PluralAttributeMapping;
|
||||
|
||||
return new StandardVirtualTableGroup( navigablePath, this, lhs, fetched );
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@ import org.hibernate.metamodel.model.domain.NavigableRole;
|
|||
import org.hibernate.query.sqm.ComparisonOperator;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
|
@ -100,9 +99,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
this.keySide = new EmbeddedForeignKeyDescriptorSide( Nature.KEY, keyMappingType );
|
||||
final List<String> columns = new ArrayList<>( keySelectableMappings.getJdbcTypeCount() );
|
||||
keySelectableMappings.forEachSelectable(
|
||||
(columnIndex, selection) -> {
|
||||
columns.add( selection.getSelectionExpression() );
|
||||
}
|
||||
(columnIndex, selection) -> columns.add( selection.getSelectionExpression() )
|
||||
);
|
||||
this.associationKey = new AssociationKey( keyTable, columns );
|
||||
this.hasConstraint = hasConstraint;
|
||||
|
@ -324,13 +321,15 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
else {
|
||||
resultNavigablePath = navigablePath.append( ForeignKeyDescriptor.TARGET_PART_NAME );
|
||||
}
|
||||
final TableGroup fkTableGroup = creationState.getSqlAstCreationState().getFromClauseAccess().resolveTableGroup(
|
||||
|
||||
creationState.getSqlAstCreationState().getFromClauseAccess().resolveTableGroup(
|
||||
resultNavigablePath,
|
||||
np -> {
|
||||
final TableGroupJoin tableGroupJoin = modelPart.createTableGroupJoin(
|
||||
resultNavigablePath,
|
||||
tableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
@ -361,8 +360,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
public Predicate generateJoinPredicate(
|
||||
TableGroup targetSideTableGroup,
|
||||
TableGroup keySideTableGroup,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final TableReference lhsTableReference = targetSideTableGroup.resolveTableReference(
|
||||
targetSideTableGroup.getNavigablePath(),
|
||||
targetTable,
|
||||
|
@ -374,33 +372,21 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor {
|
|||
false
|
||||
);
|
||||
|
||||
return generateJoinPredicate(
|
||||
lhsTableReference,
|
||||
rhsTableKeyReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
);
|
||||
return generateJoinPredicate( lhsTableReference, rhsTableKeyReference, creationState );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate generateJoinPredicate(
|
||||
TableReference targetSideReference,
|
||||
TableReference keySideReference,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final Junction predicate = new Junction( Junction.Nature.CONJUNCTION );
|
||||
targetSelectableMappings.forEachSelectable(
|
||||
(i, selection) -> {
|
||||
final ComparisonPredicate comparisonPredicate = new ComparisonPredicate(
|
||||
new ColumnReference(
|
||||
targetSideReference,
|
||||
selection
|
||||
),
|
||||
new ColumnReference( targetSideReference, selection ),
|
||||
ComparisonOperator.EQUAL,
|
||||
new ColumnReference(
|
||||
keySideReference,
|
||||
keySelectableMappings.getSelectable( i )
|
||||
)
|
||||
new ColumnReference( keySideReference, keySelectableMappings.getSelectable( i ) )
|
||||
);
|
||||
predicate.add( comparisonPredicate );
|
||||
}
|
||||
|
|
|
@ -42,11 +42,8 @@ import org.hibernate.persister.collection.CollectionPersister;
|
|||
import org.hibernate.persister.collection.mutation.CollectionMutationTarget;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.tree.from.LazyTableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||
|
@ -223,28 +220,24 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
|
|||
@Override
|
||||
public TableGroupJoin createTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup collectionTableGroup,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType = requireNonNullElse( requestedJoinType, SqlAstJoinType.INNER );
|
||||
|
||||
final LazyTableGroup lazyTableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
collectionTableGroup,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
final TableGroupJoin join = new TableGroupJoin(
|
||||
|
@ -259,9 +252,8 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
|
|||
join.applyPredicate(
|
||||
foreignKey.generateJoinPredicate(
|
||||
partTableGroup.getPrimaryTableReference(),
|
||||
collectionTableGroup.resolveTableReference( foreignKey.getKeyTable() ),
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
lhs.resolveTableReference( foreignKey.getKeyTable() ),
|
||||
creationState
|
||||
)
|
||||
);
|
||||
} );
|
||||
|
@ -274,16 +266,19 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType = requireNonNullElse( requestedJoinType, SqlAstJoinType.INNER );
|
||||
final SqlAliasBase sqlAliasBase = aliasBaseGenerator.createSqlAliasBase( getSqlAliasStem() );
|
||||
final boolean canUseInnerJoin = joinType == SqlAstJoinType.INNER || lhs.canUseInnerJoins();
|
||||
final SqlAliasBase sqlAliasBase = SqlAliasBase.from(
|
||||
explicitSqlAliasBase,
|
||||
explicitSourceAlias,
|
||||
this,
|
||||
creationState.getSqlAliasBaseGenerator()
|
||||
);
|
||||
|
||||
final LazyTableGroup lazyTableGroup = new LazyTableGroup(
|
||||
canUseInnerJoin,
|
||||
|
@ -295,8 +290,7 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
|
|||
fetched,
|
||||
null,
|
||||
sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
),
|
||||
(np, tableExpression) -> {
|
||||
if ( ! foreignKey.getKeyTable().equals( tableExpression ) ) {
|
||||
|
@ -319,7 +313,7 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
|
|||
this,
|
||||
explicitSourceAlias,
|
||||
sqlAliasBase,
|
||||
creationContext.getSessionFactory(),
|
||||
creationState.getCreationContext().getSessionFactory(),
|
||||
lhs
|
||||
);
|
||||
|
||||
|
@ -334,8 +328,7 @@ public class ManyToManyCollectionPart extends AbstractEntityCollectionPart imple
|
|||
foreignKey.generateJoinPredicate(
|
||||
tableGroup.getPrimaryTableReference(),
|
||||
keySideTableReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -22,11 +22,8 @@ import org.hibernate.metamodel.mapping.SelectableMapping;
|
|||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.tree.from.OneToManyTableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||
|
@ -151,17 +148,15 @@ public class OneToManyCollectionPart extends AbstractEntityCollectionPart implem
|
|||
@Override
|
||||
public TableGroupJoin createTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup collectionTableGroup,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType = requireNonNullElse( requestedJoinType, SqlAstJoinType.INNER );
|
||||
final TableGroup elementTableGroup = ( (OneToManyTableGroup) collectionTableGroup ).getElementTableGroup();
|
||||
final TableGroup elementTableGroup = ( (OneToManyTableGroup) lhs ).getElementTableGroup();
|
||||
|
||||
// INDEX is implied if mapKeyPropertyName is not null
|
||||
if ( mapKeyPropertyName != null ) {
|
||||
|
@ -176,14 +171,12 @@ public class OneToManyCollectionPart extends AbstractEntityCollectionPart implem
|
|||
elementTableGroup,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
fetched,
|
||||
addsPredicate,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
fromClauseAccess.registerTableGroup( mapKeyPropertyPath, tableGroupJoin.getJoinedGroup() );
|
||||
creationState.getFromClauseAccess().registerTableGroup( mapKeyPropertyPath, tableGroupJoin.getJoinedGroup() );
|
||||
return tableGroupJoin;
|
||||
}
|
||||
}
|
||||
|
@ -196,21 +189,18 @@ public class OneToManyCollectionPart extends AbstractEntityCollectionPart implem
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
return createTableGroupInternal(
|
||||
true,
|
||||
navigablePath,
|
||||
fetched,
|
||||
explicitSourceAlias,
|
||||
aliasBaseGenerator.createSqlAliasBase( getSqlAliasStem() ),
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() ),
|
||||
creationState
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -220,9 +210,15 @@ public class OneToManyCollectionPart extends AbstractEntityCollectionPart implem
|
|||
boolean fetched,
|
||||
String sourceAlias,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return createTableGroupInternal( canUseInnerJoins, append, fetched, sourceAlias, sqlAliasBase, sqlExpressionResolver, creationContext );
|
||||
SqlAstCreationState creationState) {
|
||||
return createTableGroupInternal(
|
||||
canUseInnerJoins,
|
||||
append,
|
||||
fetched,
|
||||
sourceAlias,
|
||||
sqlAliasBase,
|
||||
creationState
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,9 +46,7 @@ import org.hibernate.spi.NavigablePath;
|
|||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasStemHelper;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
|
@ -495,17 +493,18 @@ public class PluralAttributeMappingImpl
|
|||
private TableGroup resolveCollectionTableGroup(
|
||||
FetchParent fetchParent,
|
||||
NavigablePath fetchablePath,
|
||||
DomainResultCreationState creationState, SqlAstCreationState sqlAstCreationState) {
|
||||
DomainResultCreationState creationState,
|
||||
SqlAstCreationState sqlAstCreationState) {
|
||||
final FromClauseAccess fromClauseAccess = sqlAstCreationState.getFromClauseAccess();
|
||||
return fromClauseAccess.resolveTableGroup(
|
||||
fetchablePath,
|
||||
p -> {
|
||||
final TableGroup lhsTableGroup = fromClauseAccess.getTableGroup(
|
||||
fetchParent.getNavigablePath() );
|
||||
final TableGroup lhsTableGroup = fromClauseAccess.getTableGroup( fetchParent.getNavigablePath() );
|
||||
final TableGroupJoin tableGroupJoin = createTableGroupJoin(
|
||||
fetchablePath,
|
||||
lhsTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.LEFT,
|
||||
true,
|
||||
false,
|
||||
|
@ -566,13 +565,11 @@ public class PluralAttributeMappingImpl
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType;
|
||||
if ( requestedJoinType == null ) {
|
||||
if ( fetched ) {
|
||||
|
@ -590,13 +587,11 @@ public class PluralAttributeMappingImpl
|
|||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
predicates::add,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
final TableGroupJoin tableGroupJoin = new TableGroupJoin(
|
||||
navigablePath,
|
||||
|
@ -613,21 +608,17 @@ public class PluralAttributeMappingImpl
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
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;
|
||||
}
|
||||
SqlAstCreationState creationState) {
|
||||
final CollectionPersister collectionDescriptor = getCollectionDescriptor();
|
||||
final SqlAstJoinType joinType = requestedJoinType == null
|
||||
? SqlAstJoinType.INNER
|
||||
: requestedJoinType;
|
||||
final SqlAliasBase sqlAliasBase = creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() );
|
||||
|
||||
final TableGroup tableGroup;
|
||||
if ( collectionDescriptor.isOneToMany() ) {
|
||||
tableGroup = createOneToManyTableGroup(
|
||||
|
@ -635,10 +626,8 @@ public class PluralAttributeMappingImpl
|
|||
navigablePath,
|
||||
fetched,
|
||||
explicitSourceAlias,
|
||||
aliasBaseGenerator.createSqlAliasBase( getSqlAliasStem() ),
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
sqlAliasBase,
|
||||
creationState
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -647,22 +636,13 @@ public class PluralAttributeMappingImpl
|
|||
navigablePath,
|
||||
fetched,
|
||||
explicitSourceAlias,
|
||||
aliasBaseGenerator.createSqlAliasBase( getSqlAliasStem() ),
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
sqlAliasBase,
|
||||
creationState
|
||||
);
|
||||
}
|
||||
|
||||
if ( predicateConsumer != null ) {
|
||||
predicateConsumer.accept(
|
||||
getKeyDescriptor().generateJoinPredicate(
|
||||
lhs,
|
||||
tableGroup,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
)
|
||||
);
|
||||
predicateConsumer.accept( getKeyDescriptor().generateJoinPredicate( lhs, tableGroup, creationState ) );
|
||||
}
|
||||
return tableGroup;
|
||||
}
|
||||
|
@ -677,24 +657,26 @@ public class PluralAttributeMappingImpl
|
|||
NavigablePath navigablePath,
|
||||
boolean fetched,
|
||||
String sourceAlias,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAliasBase sqlAliasBase = SqlAliasBase.from(
|
||||
explicitSqlAliasBase,
|
||||
sourceAlias,
|
||||
this,
|
||||
creationState.getSqlAliasBaseGenerator()
|
||||
);
|
||||
final TableGroup elementTableGroup = ( (OneToManyCollectionPart) elementDescriptor ).createAssociatedTableGroup(
|
||||
canUseInnerJoins,
|
||||
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
|
||||
fetched,
|
||||
sourceAlias,
|
||||
sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
final OneToManyTableGroup tableGroup = new OneToManyTableGroup(
|
||||
this,
|
||||
elementTableGroup,
|
||||
// this::createIndexTableGroup,
|
||||
creationContext.getSessionFactory()
|
||||
creationState.getCreationContext().getSessionFactory()
|
||||
);
|
||||
|
||||
if ( indexDescriptor instanceof TableGroupJoinProducer ) {
|
||||
|
@ -702,13 +684,11 @@ public class PluralAttributeMappingImpl
|
|||
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
|
||||
tableGroup,
|
||||
null,
|
||||
sqlAliasBase,
|
||||
SqlAstJoinType.INNER,
|
||||
fetched,
|
||||
false,
|
||||
stem -> sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
tableGroup.registerIndexTableGroup( tableGroupJoin );
|
||||
}
|
||||
|
@ -721,12 +701,15 @@ public class PluralAttributeMappingImpl
|
|||
NavigablePath navigablePath,
|
||||
boolean fetched,
|
||||
String sourceAlias,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstCreationState creationState) {
|
||||
assert !getCollectionDescriptor().isOneToMany();
|
||||
|
||||
final SqlAliasBase sqlAliasBase = SqlAliasBase.from(
|
||||
explicitSqlAliasBase,
|
||||
sourceAlias,
|
||||
this,
|
||||
creationState.getSqlAliasBaseGenerator()
|
||||
);
|
||||
final String collectionTableName = ( (Joinable) collectionDescriptor ).getTableName();
|
||||
final TableReference collectionTableReference = new NamedTableReference(
|
||||
collectionTableName,
|
||||
|
@ -745,7 +728,7 @@ public class PluralAttributeMappingImpl
|
|||
sqlAliasBase,
|
||||
s -> false,
|
||||
null,
|
||||
creationContext.getSessionFactory()
|
||||
creationState.getCreationContext().getSessionFactory()
|
||||
);
|
||||
|
||||
if ( elementDescriptor instanceof TableGroupJoinProducer ) {
|
||||
|
@ -753,13 +736,11 @@ public class PluralAttributeMappingImpl
|
|||
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
|
||||
tableGroup,
|
||||
null,
|
||||
sqlAliasBase,
|
||||
SqlAstJoinType.INNER,
|
||||
fetched,
|
||||
false,
|
||||
stem -> sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
tableGroup.registerElementTableGroup( tableGroupJoin );
|
||||
}
|
||||
|
@ -769,13 +750,11 @@ public class PluralAttributeMappingImpl
|
|||
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
|
||||
tableGroup,
|
||||
null,
|
||||
sqlAliasBase,
|
||||
SqlAstJoinType.INNER,
|
||||
fetched,
|
||||
false,
|
||||
stem -> sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
tableGroup.registerIndexTableGroup( tableGroupJoin );
|
||||
}
|
||||
|
@ -788,41 +767,16 @@ public class PluralAttributeMappingImpl
|
|||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAstCreationState creationState,
|
||||
SqlAstCreationContext creationContext) {
|
||||
return createRootTableGroup(
|
||||
canUseInnerJoins,
|
||||
navigablePath,
|
||||
explicitSourceAlias,
|
||||
additionalPredicateCollectorAccess,
|
||||
creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() ),
|
||||
creationState.getSqlExpressionResolver(),
|
||||
creationState.getFromClauseAccess(),
|
||||
creationContext
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableGroup createRootTableGroup(
|
||||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver expressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAliasBase explicitSqlAliasBase, Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAstCreationState creationState) {
|
||||
if ( getCollectionDescriptor().isOneToMany() ) {
|
||||
return createOneToManyTableGroup(
|
||||
canUseInnerJoins,
|
||||
navigablePath,
|
||||
false,
|
||||
explicitSourceAlias,
|
||||
sqlAliasBase,
|
||||
expressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
explicitSqlAliasBase,
|
||||
creationState
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -831,10 +785,8 @@ public class PluralAttributeMappingImpl
|
|||
navigablePath,
|
||||
false,
|
||||
explicitSourceAlias,
|
||||
sqlAliasBase,
|
||||
expressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
explicitSqlAliasBase,
|
||||
creationState
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.query.sqm.ComparisonOperator;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
|
@ -339,18 +338,11 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
|||
public Predicate generateJoinPredicate(
|
||||
TableReference targetSideReference,
|
||||
TableReference keySideReference,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
return new ComparisonPredicate(
|
||||
new ColumnReference(
|
||||
targetSideReference,
|
||||
targetSide.getModelPart()
|
||||
),
|
||||
new ColumnReference( targetSideReference, targetSide.getModelPart() ),
|
||||
ComparisonOperator.EQUAL,
|
||||
new ColumnReference(
|
||||
keySideReference,
|
||||
keySide.getModelPart()
|
||||
)
|
||||
new ColumnReference( keySideReference, keySide.getModelPart() )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -358,8 +350,7 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
|||
public Predicate generateJoinPredicate(
|
||||
TableGroup targetSideTableGroup,
|
||||
TableGroup keySideTableGroup,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final TableReference lhsTableReference = targetSideTableGroup.resolveTableReference(
|
||||
targetSideTableGroup.getNavigablePath(),
|
||||
targetSide.getModelPart().getContainingTableExpression(),
|
||||
|
@ -371,12 +362,7 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
|
|||
false
|
||||
);
|
||||
|
||||
return generateJoinPredicate(
|
||||
lhsTableReference,
|
||||
rhsTableKeyReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
);
|
||||
return generateJoinPredicate( lhsTableReference, rhsTableKeyReference, creationState );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -62,11 +62,8 @@ import org.hibernate.spi.TreatedNavigablePath;
|
|||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasStemHelper;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.from.CorrelatedTableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.LazyTableGroup;
|
||||
|
@ -1488,6 +1485,7 @@ public class ToOneAttributeMapping
|
|||
fetchablePath,
|
||||
parentTableGroup,
|
||||
resultVariable,
|
||||
null,
|
||||
joinType,
|
||||
true,
|
||||
false,
|
||||
|
@ -1539,6 +1537,7 @@ public class ToOneAttributeMapping
|
|||
navigablePath,
|
||||
tableGroup,
|
||||
null,
|
||||
null,
|
||||
getDefaultSqlAstJoinType( tableGroup ),
|
||||
true,
|
||||
false,
|
||||
|
@ -1663,13 +1662,11 @@ public class ToOneAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
// Make sure the lhs is never a plural table group directly, but always a table group for a part
|
||||
// This is vital for the map key property check that comes next
|
||||
assert !( lhs instanceof PluralTableGroup );
|
||||
|
@ -1687,6 +1684,8 @@ public class ToOneAttributeMapping
|
|||
joinType = requestedJoinType;
|
||||
}
|
||||
|
||||
final FromClauseAccess fromClauseAccess = creationState.getFromClauseAccess();
|
||||
|
||||
// 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 ( !addsPredicate && ( joinType == SqlAstJoinType.INNER || joinType == SqlAstJoinType.LEFT ) ) {
|
||||
|
@ -1770,14 +1769,13 @@ public class ToOneAttributeMapping
|
|||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
final TableGroupJoin join = new TableGroupJoin(
|
||||
navigablePath,
|
||||
joinType,
|
||||
|
@ -1803,8 +1801,7 @@ public class ToOneAttributeMapping
|
|||
join.applyPredicate( foreignKeyDescriptor.generateJoinPredicate(
|
||||
targetTableReference,
|
||||
keyTableReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
) );
|
||||
|
||||
if ( hasNotFoundAction() ) {
|
||||
|
@ -1826,14 +1823,17 @@ public class ToOneAttributeMapping
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAliasBase sqlAliasBase = aliasBaseGenerator.createSqlAliasBase( sqlAliasStem );
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAliasBase sqlAliasBase = SqlAliasBase.from(
|
||||
explicitSqlAliasBase,
|
||||
explicitSourceAlias,
|
||||
this,
|
||||
creationState.getSqlAliasBaseGenerator()
|
||||
);
|
||||
|
||||
final boolean canUseInnerJoin;
|
||||
if ( ! lhs.canUseInnerJoins() ) {
|
||||
|
@ -1847,9 +1847,11 @@ public class ToOneAttributeMapping
|
|||
}
|
||||
|
||||
TableGroup realParentTableGroup = lhs;
|
||||
final FromClauseAccess fromClauseAccess = creationState.getFromClauseAccess();
|
||||
while ( realParentTableGroup.getModelPart() instanceof EmbeddableValuedModelPart ) {
|
||||
realParentTableGroup = fromClauseAccess.findTableGroup( realParentTableGroup.getNavigablePath().getParent() );
|
||||
}
|
||||
|
||||
final TableGroupProducer tableGroupProducer;
|
||||
if ( realParentTableGroup instanceof CorrelatedTableGroup ) {
|
||||
// If the parent is a correlated table group, we can't refer to columns of the table in the outer query,
|
||||
|
@ -1860,6 +1862,7 @@ public class ToOneAttributeMapping
|
|||
else {
|
||||
tableGroupProducer = this;
|
||||
}
|
||||
|
||||
final LazyTableGroup lazyTableGroup = new LazyTableGroup(
|
||||
canUseInnerJoin,
|
||||
navigablePath,
|
||||
|
@ -1870,8 +1873,7 @@ public class ToOneAttributeMapping
|
|||
fetched,
|
||||
null,
|
||||
sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
),
|
||||
(np, tableExpression) -> {
|
||||
if ( !canUseParentTableGroup || tableGroupProducer != ToOneAttributeMapping.this ) {
|
||||
|
@ -1898,7 +1900,7 @@ public class ToOneAttributeMapping
|
|||
tableGroupProducer,
|
||||
explicitSourceAlias,
|
||||
sqlAliasBase,
|
||||
creationContext.getSessionFactory(),
|
||||
creationState.getCreationContext().getSessionFactory(),
|
||||
lhs
|
||||
);
|
||||
|
||||
|
@ -1913,8 +1915,7 @@ public class ToOneAttributeMapping
|
|||
foreignKeyDescriptor.generateJoinPredicate(
|
||||
sideNature == ForeignKeyDescriptor.Nature.TARGET ? lhsTableReference : tableGroup.getPrimaryTableReference(),
|
||||
sideNature == ForeignKeyDescriptor.Nature.TARGET ? tableGroup.getPrimaryTableReference() : lhsTableReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -1953,12 +1954,10 @@ public class ToOneAttributeMapping
|
|||
boolean fetched,
|
||||
String sourceAlias,
|
||||
final SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final TableReference primaryTableReference = getEntityMappingType().createPrimaryTableReference(
|
||||
sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new StandardTableGroup(
|
||||
|
@ -1975,10 +1974,9 @@ public class ToOneAttributeMapping
|
|||
tableExpression,
|
||||
sqlAliasBase,
|
||||
primaryTableReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
),
|
||||
creationContext.getSessionFactory()
|
||||
creationState.getCreationContext().getSessionFactory()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -936,11 +936,9 @@ public abstract class AbstractCollectionPersister
|
|||
true,
|
||||
entityPath,
|
||||
null,
|
||||
() -> p -> {},
|
||||
new SqlAliasBaseConstant( alias ),
|
||||
sqlAstCreationState.getSqlExpressionResolver(),
|
||||
sqlAstCreationState.getFromClauseAccess(),
|
||||
getFactory()
|
||||
() -> p -> {},
|
||||
sqlAstCreationState
|
||||
);
|
||||
|
||||
rootQuerySpec.getFromClause().addRoot( rootTableGroup );
|
||||
|
|
|
@ -218,13 +218,11 @@ import org.hibernate.sql.Alias;
|
|||
import org.hibernate.sql.Delete;
|
||||
import org.hibernate.sql.SimpleSelect;
|
||||
import org.hibernate.sql.Template;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SimpleFromClauseAccessImpl;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseConstant;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseManager;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasStemHelper;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
|
@ -1257,19 +1255,16 @@ public abstract class AbstractEntityPersister
|
|||
@Override
|
||||
public TableReference createPrimaryTableReference(
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState sqlAstCreationState) {
|
||||
return new NamedTableReference( getTableName(), sqlAliasBase.generateNewAlias() );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TableReferenceJoin createTableReferenceJoin(
|
||||
String joinTableExpression,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
TableReference lhs,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
for ( int i = 1; i < getSubclassTableSpan(); i++ ) {
|
||||
final String subclassTableName = getSubclassTableName( i );
|
||||
if ( subclassTableName.equals( joinTableExpression ) ) {
|
||||
|
@ -1279,7 +1274,7 @@ public abstract class AbstractEntityPersister
|
|||
sqlAliasBase,
|
||||
shouldInnerJoinSubclassTable( i, emptySet() ),
|
||||
getSubclassTableKeyColumns( i ),
|
||||
sqlExpressionResolver
|
||||
creationState
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1293,7 +1288,7 @@ public abstract class AbstractEntityPersister
|
|||
SqlAliasBase sqlAliasBase,
|
||||
boolean innerJoin,
|
||||
String[] targetColumns,
|
||||
SqlExpressionResolver sqlExpressionResolver) {
|
||||
SqlAstCreationState creationState) {
|
||||
final NamedTableReference joinedTableReference = new NamedTableReference(
|
||||
joinTableExpression,
|
||||
sqlAliasBase.generateNewAlias(),
|
||||
|
@ -1308,7 +1303,7 @@ public abstract class AbstractEntityPersister
|
|||
joinedTableReference,
|
||||
getKeyColumnNames(),
|
||||
targetColumns,
|
||||
sqlExpressionResolver
|
||||
creationState
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -1318,7 +1313,7 @@ public abstract class AbstractEntityPersister
|
|||
TableReference joinedTableReference,
|
||||
String[] pkColumnNames,
|
||||
String[] fkColumnNames,
|
||||
SqlExpressionResolver sqlExpressionResolver) {
|
||||
SqlAstCreationState creationState) {
|
||||
final EntityIdentifierMapping identifierMapping = getIdentifierMapping();
|
||||
|
||||
final Junction conjunction = new Junction( Junction.Nature.CONJUNCTION );
|
||||
|
@ -1329,7 +1324,7 @@ public abstract class AbstractEntityPersister
|
|||
identifierMapping.forEachSelectable(
|
||||
(columnIndex, selection) -> {
|
||||
final String rootPkColumnName = pkColumnNames[ columnIndex ];
|
||||
final Expression pkColumnExpression = sqlExpressionResolver.resolveSqlExpression(
|
||||
final Expression pkColumnExpression = creationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||
createColumnReferenceKey( rootTableReference, rootPkColumnName ),
|
||||
sqlAstProcessingState -> new ColumnReference(
|
||||
rootTableReference.getIdentificationVariable(),
|
||||
|
@ -1341,7 +1336,7 @@ public abstract class AbstractEntityPersister
|
|||
);
|
||||
|
||||
final String fkColumnName = fkColumnNames[ columnIndex ];
|
||||
final Expression fkColumnExpression = sqlExpressionResolver.resolveSqlExpression(
|
||||
final Expression fkColumnExpression = creationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||
createColumnReferenceKey( joinedTableReference, fkColumnName ),
|
||||
sqlAstProcessingState -> new ColumnReference(
|
||||
joinedTableReference.getIdentificationVariable(),
|
||||
|
@ -1693,11 +1688,9 @@ public abstract class AbstractEntityPersister
|
|||
true,
|
||||
entityPath,
|
||||
null,
|
||||
() -> p -> {},
|
||||
new SqlAliasBaseConstant( alias ),
|
||||
sqlAstCreationState.getSqlExpressionResolver(),
|
||||
sqlAstCreationState.getFromClauseAccess(),
|
||||
getFactory()
|
||||
() -> p -> {},
|
||||
sqlAstCreationState
|
||||
);
|
||||
|
||||
rootQuerySpec.getFromClause().addRoot( rootTableGroup );
|
||||
|
@ -2969,12 +2962,15 @@ public abstract class AbstractEntityPersister
|
|||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver expressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAliasBase sqlAliasBase = SqlAliasBase.from(
|
||||
explicitSqlAliasBase,
|
||||
explicitSourceAlias,
|
||||
this,
|
||||
creationState.getSqlAliasBaseGenerator()
|
||||
);
|
||||
final TableReference rootTableReference = new NamedTableReference(
|
||||
needsDiscriminator() ? getRootTableName() : getTableName(),
|
||||
sqlAliasBase.generateNewAlias()
|
||||
|
@ -3010,7 +3006,7 @@ public abstract class AbstractEntityPersister
|
|||
? getRootTableKeyColumnNames()
|
||||
: getKeyColumnNames(),
|
||||
getSubclassTableKeyColumns( i ),
|
||||
expressionResolver
|
||||
creationState
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -3022,7 +3018,7 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
if ( additionalPredicateCollectorAccess != null && needsDiscriminator() ) {
|
||||
final String alias = tableGroup.getPrimaryTableReference().getIdentificationVariable();
|
||||
final Predicate discriminatorPredicate = createDiscriminatorPredicate( alias, tableGroup, expressionResolver );
|
||||
final Predicate discriminatorPredicate = createDiscriminatorPredicate( alias, tableGroup, creationState );
|
||||
additionalPredicateCollectorAccess.get().accept( discriminatorPredicate );
|
||||
}
|
||||
|
||||
|
@ -3036,15 +3032,14 @@ public abstract class AbstractEntityPersister
|
|||
TableGroup tableGroup,
|
||||
SqlAstCreationState creationState) {
|
||||
if ( needsDiscriminator() ) {
|
||||
final SqlExpressionResolver expressionResolver = creationState.getSqlExpressionResolver();
|
||||
predicateConsumer.accept( createDiscriminatorPredicate( alias, tableGroup, expressionResolver ) );
|
||||
predicateConsumer.accept( createDiscriminatorPredicate( alias, tableGroup, creationState ) );
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate createDiscriminatorPredicate(
|
||||
String alias,
|
||||
TableGroup tableGroup,
|
||||
SqlExpressionResolver expressionResolver) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlExpressionResolver.ColumnReferenceKey columnReferenceKey;
|
||||
final String discriminatorExpression;
|
||||
if ( isDiscriminatorFormula() ) {
|
||||
|
@ -3063,7 +3058,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
final BasicType<?> discriminatorType = (BasicType<?>) getDiscriminatorMapping().getJdbcMapping();
|
||||
final Expression sqlExpression = expressionResolver.resolveSqlExpression(
|
||||
final Expression sqlExpression = creationState.getSqlExpressionResolver().resolveSqlExpression(
|
||||
columnReferenceKey,
|
||||
sqlAstProcessingState -> new ColumnReference(
|
||||
alias,
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.hibernate.cache.spi.access.EntityDataAccess;
|
|||
import org.hibernate.cache.spi.access.NaturalIdDataAccess;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.DynamicFilterAliasGenerator;
|
||||
import org.hibernate.internal.FilterAliasGenerator;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
|
@ -781,17 +780,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
|||
return isInverseTable[j];
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected boolean isSubclassTableSequentialSelect(int j) {
|
||||
// return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j];
|
||||
// }
|
||||
|
||||
/*public void postInstantiate() throws MappingException {
|
||||
super.postInstantiate();
|
||||
//TODO: other lock modes?
|
||||
loader = createEntityLoader(LockMode.NONE, CollectionHelper.EMPTY_MAP);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public String getSubclassPropertyTableName(int i) {
|
||||
return subclassTableNameClosure[subclassPropertyTableNumberClosure[i]];
|
||||
|
|
|
@ -49,10 +49,8 @@ import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
|||
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
|
||||
import org.hibernate.persister.spi.PersisterCreationContext;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.from.NamedTableReference;
|
||||
|
@ -254,11 +252,17 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UnionTableReference createPrimaryTableReference(
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver expressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
sqlAliasBase = SqlAliasBase.from(
|
||||
sqlAliasBase,
|
||||
null,
|
||||
this,
|
||||
creationState.getSqlAliasBaseGenerator()
|
||||
);
|
||||
return new UnionTableReference( getTableName(), subclassTableExpressions, sqlAliasBase.generateNewAlias() );
|
||||
}
|
||||
|
||||
|
@ -267,15 +271,13 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
|
|||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver expressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAstCreationState creationState) {
|
||||
return new UnionTableGroup(
|
||||
canUseInnerJoins,
|
||||
navigablePath,
|
||||
createPrimaryTableReference( sqlAliasBase, expressionResolver, creationContext ),
|
||||
createPrimaryTableReference( sqlAliasBase, creationState ),
|
||||
this,
|
||||
explicitSourceAlias
|
||||
);
|
||||
|
|
|
@ -38,11 +38,8 @@ import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
|
|||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.Clause;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
|
@ -270,25 +267,21 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType = requestedJoinType == null ? SqlAstJoinType.INNER : requestedJoinType;
|
||||
final TableGroup tableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new TableGroupJoin( navigablePath, joinType, tableGroup );
|
||||
|
@ -299,13 +292,11 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
return new StandardVirtualTableGroup(
|
||||
navigablePath,
|
||||
this,
|
||||
|
|
|
@ -49,10 +49,8 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
import org.hibernate.query.sqm.ComparisonOperator;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
|
@ -239,27 +237,22 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType requestedJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory();
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAstJoinType joinType = requireNonNullElse( requestedJoinType, SqlAstJoinType.INNER );
|
||||
|
||||
final LazyTableGroup lazyTableGroup = createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
explicitSqlAliasBase,
|
||||
requestedJoinType,
|
||||
fetched,
|
||||
null,
|
||||
aliasBaseGenerator,
|
||||
sqlExpressionResolver,
|
||||
fromClauseAccess,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
final TableGroupJoin tableGroupJoin = new TableGroupJoin(
|
||||
navigablePath,
|
||||
|
@ -270,9 +263,8 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
lazyTableGroup.setTableGroupInitializerCallback(
|
||||
createTableGroupInitializerCallback(
|
||||
lhs,
|
||||
sqlExpressionResolver,
|
||||
sessionFactory,
|
||||
tableGroupJoin::applyPredicate
|
||||
tableGroupJoin::applyPredicate,
|
||||
creationState
|
||||
)
|
||||
);
|
||||
return tableGroupJoin;
|
||||
|
@ -280,9 +272,8 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
|
||||
private Consumer<TableGroup> createTableGroupInitializerCallback(
|
||||
TableGroup lhs,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
Consumer<Predicate> predicateConsumer) {
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAstCreationState creationState) {
|
||||
// -----------------
|
||||
// Collect the selectable mappings for the FK key side and target side
|
||||
// As we will "resolve" the derived column references for these mappings
|
||||
|
@ -291,6 +282,8 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
final List<SelectableMapping> keyMappings;
|
||||
final List<SelectableMapping> targetMappings;
|
||||
|
||||
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlExpressionResolver();
|
||||
|
||||
if ( delegate instanceof OneToManyCollectionPart ) {
|
||||
final OneToManyCollectionPart oneToMany = (OneToManyCollectionPart) delegate;
|
||||
final PluralAttributeMapping pluralAttribute = oneToMany.getCollectionDescriptor().getAttributeMapping();
|
||||
|
@ -407,13 +400,11 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
boolean fetched,
|
||||
String sourceAlias,
|
||||
final SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
SqlAstCreationContext creationContext) {
|
||||
SqlAstCreationState creationState) {
|
||||
final EntityMappingType entityMappingType = delegate.getEntityMappingType();
|
||||
final TableReference primaryTableReference = entityMappingType.createPrimaryTableReference(
|
||||
sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
);
|
||||
|
||||
return new StandardTableGroup(
|
||||
|
@ -430,10 +421,9 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
tableExpression,
|
||||
sqlAliasBase,
|
||||
primaryTableReference,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
),
|
||||
creationContext.getSessionFactory()
|
||||
creationState.getCreationContext().getSessionFactory()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -442,14 +432,17 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext) {
|
||||
final SqlAliasBase sqlAliasBase = aliasBaseGenerator.createSqlAliasBase( getSqlAliasStem() );
|
||||
SqlAstCreationState creationState) {
|
||||
final SqlAliasBase sqlAliasBase = SqlAliasBase.from(
|
||||
explicitSqlAliasBase,
|
||||
explicitSourceAlias,
|
||||
this,
|
||||
creationState.getSqlAliasBaseGenerator()
|
||||
);
|
||||
final boolean canUseInnerJoin = sqlAstJoinType == SqlAstJoinType.INNER || lhs.canUseInnerJoins();
|
||||
final EntityPersister entityPersister = delegate.getEntityMappingType().getEntityPersister();
|
||||
final LazyTableGroup lazyTableGroup = new LazyTableGroup(
|
||||
|
@ -462,8 +455,7 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
fetched,
|
||||
null,
|
||||
sqlAliasBase,
|
||||
sqlExpressionResolver,
|
||||
creationContext
|
||||
creationState
|
||||
),
|
||||
(np, tableExpression) -> {
|
||||
if ( !tableExpression.isEmpty() && !entityPersister.containsTableReference( tableExpression ) ) {
|
||||
|
@ -485,18 +477,13 @@ public class AnonymousTupleEntityValuedModelPart
|
|||
this,
|
||||
explicitSourceAlias,
|
||||
sqlAliasBase,
|
||||
creationContext.getSessionFactory(),
|
||||
creationState.getCreationContext().getSessionFactory(),
|
||||
lhs
|
||||
);
|
||||
|
||||
if ( predicateConsumer != null ) {
|
||||
lazyTableGroup.setTableGroupInitializerCallback(
|
||||
createTableGroupInitializerCallback(
|
||||
lhs,
|
||||
sqlExpressionResolver,
|
||||
creationContext.getSessionFactory(),
|
||||
predicateConsumer
|
||||
)
|
||||
createTableGroupInitializerCallback( lhs, predicateConsumer, creationState )
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ public class QualifiedJoinPathConsumer implements DotIdentifierConsumer {
|
|||
final SqmJoin<Object, Object> join = ( (SqmJoinable<Object, Object>) subPathSource ).createSqmJoin(
|
||||
lhs,
|
||||
joinType,
|
||||
isTerminal ? alias : allowReuse ? SqmCreationHelper.IMPLICIT_ALIAS : Long.toString( System.nanoTime() ),
|
||||
isTerminal ? alias : allowReuse ? SqmCreationHelper.IMPLICIT_ALIAS : null,
|
||||
fetch,
|
||||
creationState
|
||||
);
|
||||
|
|
|
@ -10,22 +10,19 @@ import java.util.Arrays;
|
|||
import java.util.function.BiFunction;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.SelectableConsumer;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||
import org.hibernate.query.results.FromClauseAccessImpl;
|
||||
import org.hibernate.query.results.ResultBuilder;
|
||||
import org.hibernate.query.results.ResultsHelper;
|
||||
import org.hibernate.query.results.ResultSetMappingSqlSelection;
|
||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseConstant;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.results.graph.DomainResult;
|
||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||
|
@ -105,11 +102,9 @@ public class CompleteResultBuilderCollectionStandard implements CompleteResultBu
|
|||
false,
|
||||
navigablePath,
|
||||
tableAlias,
|
||||
null,
|
||||
new SqlAliasBaseConstant( tableAlias ),
|
||||
creationStateImpl.getSqlExpressionResolver(),
|
||||
creationStateImpl.getFromClauseAccess(),
|
||||
sessionFactory
|
||||
null,
|
||||
creationStateImpl
|
||||
);
|
||||
fromClauseAccess.registerTableGroup( navigablePath, rootTableGroup );
|
||||
|
||||
|
|
|
@ -14,13 +14,13 @@ import java.util.function.BiFunction;
|
|||
import org.hibernate.LockMode;
|
||||
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.query.results.BasicValuedFetchBuilder;
|
||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||
import org.hibernate.query.results.FetchBuilder;
|
||||
import org.hibernate.query.results.ResultBuilder;
|
||||
import org.hibernate.query.results.ResultsHelper;
|
||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||
import org.hibernate.sql.results.graph.entity.EntityResult;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
||||
|
@ -105,8 +105,8 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti
|
|||
navigablePath,
|
||||
null,
|
||||
null,
|
||||
impl.getSqlAstCreationState(),
|
||||
impl.getSqlAstCreationState().getCreationContext()
|
||||
null,
|
||||
impl.getSqlAstCreationState()
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -138,11 +138,9 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde
|
|||
true,
|
||||
navigablePath,
|
||||
tableAlias,
|
||||
null,
|
||||
new SqlAliasBaseConstant( tableAlias ),
|
||||
impl.getSqlExpressionResolver(),
|
||||
impl.getFromClauseAccess(),
|
||||
impl.getCreationContext()
|
||||
null,
|
||||
impl
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -64,9 +64,9 @@ public class EntityResultImpl implements EntityResult {
|
|||
true,
|
||||
navigablePath,
|
||||
null,
|
||||
null,
|
||||
() -> p -> {},
|
||||
sqlAstCreationState,
|
||||
sqlAstCreationState.getCreationContext().getSessionFactory()
|
||||
sqlAstCreationState
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -18,20 +18,17 @@ import org.hibernate.engine.FetchTiming;
|
|||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||
import org.hibernate.query.results.FetchBuilder;
|
||||
import org.hibernate.query.results.ResultsHelper;
|
||||
import org.hibernate.query.results.ResultSetMappingSqlSelection;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseConstant;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
|
||||
|
@ -39,11 +36,9 @@ import org.hibernate.sql.ast.tree.from.TableReference;
|
|||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||
import org.hibernate.sql.results.graph.Fetch;
|
||||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
import org.hibernate.sql.results.graph.Fetchable;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
||||
|
||||
import static org.hibernate.query.results.ResultsHelper.impl;
|
||||
import static org.hibernate.sql.ast.spi.SqlExpressionResolver.createColumnReferenceKey;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -145,13 +140,11 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue
|
|||
fetchPath,
|
||||
ownerTableGroup,
|
||||
tableAlias,
|
||||
sqlAliasBase,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
s -> sqlAliasBase,
|
||||
creationState.getSqlExpressionResolver(),
|
||||
creationState.getFromClauseAccess(),
|
||||
creationState.getCreationContext()
|
||||
creationState
|
||||
);
|
||||
ownerTableGroup.addTableGroupJoin( tableGroupJoin );
|
||||
creationState.getFromClauseAccess().registerTableGroup( fetchPath, tableGroup = tableGroupJoin.getJoinedGroup() );
|
||||
|
|
|
@ -12,9 +12,9 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||
import org.hibernate.query.results.ResultsHelper;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseConstant;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||
|
@ -121,11 +121,9 @@ public class DynamicResultBuilderEntityCalculated implements DynamicResultBuilde
|
|||
true,
|
||||
navigablePath,
|
||||
tableAlias,
|
||||
null,
|
||||
new SqlAliasBaseConstant( tableAlias ),
|
||||
creationStateImpl,
|
||||
creationStateImpl.getFromClauseAccess(),
|
||||
creationStateImpl.getCreationContext()
|
||||
null,
|
||||
creationStateImpl
|
||||
);
|
||||
|
||||
creationStateImpl.getFromClauseAccess().registerTableGroup( navigablePath, tableGroup );
|
||||
|
|
|
@ -198,8 +198,7 @@ public class DynamicResultBuilderEntityStandard
|
|||
np -> {
|
||||
final TableReference tableReference = entityMapping.createPrimaryTableReference(
|
||||
new SqlAliasBaseConstant( tableAlias ),
|
||||
creationState.getSqlExpressionResolver(),
|
||||
creationState.getCreationContext()
|
||||
creationState
|
||||
);
|
||||
|
||||
if ( lockMode != null ) {
|
||||
|
|
|
@ -59,6 +59,7 @@ public class ImplicitFetchBuilderDiscriminatedAssociation implements ImplicitFet
|
|||
fetchPath,
|
||||
parentTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
|
|
@ -6,11 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.query.results.implicit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
@ -18,13 +15,12 @@ import java.util.function.Function;
|
|||
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.query.results.Builders;
|
||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||
import org.hibernate.query.results.FetchBuilder;
|
||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||
|
@ -112,6 +108,7 @@ public class ImplicitFetchBuilderEmbeddable implements ImplicitFetchBuilder {
|
|||
fetchPath,
|
||||
parentTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
|
|
@ -74,6 +74,7 @@ public class ImplicitModelPartResultBuilderEmbeddable
|
|||
navigablePath,
|
||||
parentTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
|
|
@ -73,8 +73,8 @@ public class ImplicitModelPartResultBuilderEntity
|
|||
navigablePath,
|
||||
null,
|
||||
null,
|
||||
creationStateImpl,
|
||||
creationStateImpl.getCreationContext()
|
||||
null,
|
||||
creationStateImpl
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -343,7 +343,6 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
|
|||
true
|
||||
);
|
||||
|
||||
// tableGroupAccess = sqmConverter.getFromClauseAccess();
|
||||
final SqmTranslation<SelectStatement> sqmInterpretation = sqmConverter.translate();
|
||||
final FromClauseAccess tableGroupAccess = sqmConverter.getFromClauseAccess();
|
||||
|
||||
|
|
|
@ -116,11 +116,12 @@ public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter<Sta
|
|||
true,
|
||||
sqmRoot.getNavigablePath(),
|
||||
sourceAlias,
|
||||
() -> predicate -> {
|
||||
null,
|
||||
() -> (predicate) -> {
|
||||
this.discriminatorPredicate = predicate;
|
||||
},
|
||||
this,
|
||||
creationContext.getSessionFactory() );
|
||||
this
|
||||
);
|
||||
|
||||
getFromClauseAccess().registerTableGroup( sqmRoot.getNavigablePath(), mutatingTableGroup );
|
||||
}
|
||||
|
@ -145,8 +146,7 @@ public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter<Sta
|
|||
}
|
||||
|
||||
/**
|
||||
* Specialized hook to visit the assignments defined by the update SQM allow
|
||||
* "listening" for each SQL assignment.
|
||||
* Specialized hook to visit the assignments defined by the update SQM.
|
||||
*/
|
||||
public void visitSetClause(
|
||||
SqmSetClause setClause,
|
||||
|
@ -165,8 +165,7 @@ public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter<Sta
|
|||
}
|
||||
|
||||
/**
|
||||
* Specialized hook to visit the assignments defined by the update SQM allow
|
||||
* "listening" for each SQL assignment.
|
||||
* Specialized hook to visit the target paths defined by the insert SQM.
|
||||
*/
|
||||
public AdditionalInsertValues visitInsertionTargetPaths(
|
||||
BiConsumer<Assignable, List<ColumnReference>> targetColumnReferenceConsumer,
|
||||
|
|
|
@ -147,13 +147,9 @@ public class InlineUpdateHandler implements UpdateHandler {
|
|||
final Object[] id = (Object[]) ids.get( i );
|
||||
final List<Expression> tupleElements = new ArrayList<>( jdbcTypeCount );
|
||||
inListExpressions.add( new SqlTuple( tupleElements, identifierMapping ) );
|
||||
identifierMapping.forEachJdbcType(
|
||||
(index, jdbcMapping) -> {
|
||||
tupleElements.add(
|
||||
new QueryLiteral<>( id[index], (BasicValuedMapping) jdbcMapping )
|
||||
);
|
||||
}
|
||||
);
|
||||
identifierMapping.forEachJdbcType( (index, jdbcMapping) -> {
|
||||
tupleElements.add( new QueryLiteral<>( id[index], (BasicValuedMapping) jdbcMapping ) );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,12 +352,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
|||
tableKeyColumnVisitationSupplier.get().accept(
|
||||
(columnIndex, selection) -> {
|
||||
assert selection.getContainingTableExpression().equals( tableExpression );
|
||||
keyColumnCollector.apply(
|
||||
new ColumnReference(
|
||||
(String) null,
|
||||
selection
|
||||
)
|
||||
);
|
||||
keyColumnCollector.apply( new ColumnReference( (String) null, selection ) );
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -375,11 +366,7 @@ public class InlineUpdateHandler implements UpdateHandler {
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Create the SQL AST and convert it into a JdbcOperation
|
||||
final NamedTableReference dmlTableReference = resolveUnionTableReference( updatingTableReference, tableExpression );
|
||||
final UpdateStatement sqlAst = new UpdateStatement(
|
||||
dmlTableReference,
|
||||
assignments,
|
||||
idListPredicate
|
||||
);
|
||||
final UpdateStatement sqlAst = new UpdateStatement( dmlTableReference, assignments, idListPredicate );
|
||||
|
||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
|
@ -430,11 +417,9 @@ public class InlineUpdateHandler implements UpdateHandler {
|
|||
true,
|
||||
updatingTableGroup.getNavigablePath(),
|
||||
updatingTableGroup.getSourceAlias(),
|
||||
() -> predicate -> {},
|
||||
new SqlAliasBaseImpl( updatingTableGroup.getGroupAlias() ),
|
||||
null,
|
||||
null,
|
||||
sessionFactory
|
||||
() -> predicate -> {},
|
||||
null
|
||||
);
|
||||
final List<String> columnNames;
|
||||
final Predicate joinPredicate;
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
|
|||
import org.hibernate.query.sqm.mutation.internal.TableKeyExpressionCollector;
|
||||
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.expression.ColumnReference;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
|
@ -54,6 +55,7 @@ import org.hibernate.sql.ast.tree.select.SelectClause;
|
|||
import org.hibernate.sql.ast.tree.update.Assignment;
|
||||
import org.hibernate.sql.ast.tree.update.UpdateStatement;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.exec.spi.JdbcMutationExecutor;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert;
|
||||
import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
|
||||
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||
|
@ -233,6 +235,11 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
|||
int expectedUpdateCount,
|
||||
QuerySpec idTableSubQuery,
|
||||
ExecutionContext executionContext) {
|
||||
|
||||
// update `updatingTableReference`
|
||||
// set ...
|
||||
// where `keyExpression` in ( `idTableSubQuery` )
|
||||
|
||||
final TableReference updatingTableReference = updatingTableGroup.getTableReference(
|
||||
updatingTableGroup.getNavigablePath(),
|
||||
tableExpression,
|
||||
|
@ -246,49 +253,188 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// create the in-subquery predicate to restrict the updates to just
|
||||
// matching ids
|
||||
|
||||
final TableKeyExpressionCollector keyColumnCollector = new TableKeyExpressionCollector( entityDescriptor );
|
||||
|
||||
tableKeyColumnVisitationSupplier.get().accept(
|
||||
(columnIndex, selection) -> {
|
||||
assert selection.getContainingTableExpression().equals( tableExpression );
|
||||
keyColumnCollector.apply(
|
||||
new ColumnReference(
|
||||
(String) null,
|
||||
selection
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
final Expression keyExpression = keyColumnCollector.buildKeyExpression();
|
||||
final InSubQueryPredicate idTableSubQueryPredicate = new InSubQueryPredicate(
|
||||
keyExpression,
|
||||
idTableSubQuery,
|
||||
false
|
||||
);
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Create the SQL AST and convert it into a JdbcOperation
|
||||
final NamedTableReference dmlTableReference = resolveUnionTableReference( updatingTableReference, tableExpression );
|
||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcServices.getJdbcEnvironment().getSqlAstTranslatorFactory();
|
||||
final JdbcMutationExecutor jdbcMutationExecutor = jdbcServices.getJdbcMutationExecutor();
|
||||
|
||||
final Expression keyExpression = resolveMutatingTableKeyExpression( tableExpression, tableKeyColumnVisitationSupplier );
|
||||
|
||||
final int updateCount = executeUpdate( idTableSubQuery, executionContext, assignments, dmlTableReference, sqlAstTranslatorFactory, jdbcMutationExecutor, keyExpression );
|
||||
|
||||
// We are done when the update count matches
|
||||
if ( updateCount == expectedUpdateCount ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the table is optional, execute an insert
|
||||
if ( isTableOptional( tableExpression ) ) {
|
||||
final int insertCount = executeInsert(
|
||||
tableExpression,
|
||||
dmlTableReference,
|
||||
keyExpression,
|
||||
tableKeyColumnVisitationSupplier,
|
||||
idTableSubQuery,
|
||||
assignments,
|
||||
sqlAstTranslatorFactory,
|
||||
jdbcMutationExecutor,
|
||||
executionContext
|
||||
);
|
||||
assert insertCount + updateCount == expectedUpdateCount;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTableOptional(String tableExpression) {
|
||||
final AbstractEntityPersister entityPersister = (AbstractEntityPersister) entityDescriptor.getEntityPersister();
|
||||
for ( int i = 0; i < entityPersister.getTableSpan(); i++ ) {
|
||||
if ( tableExpression.equals( entityPersister.getTableName( i ) )
|
||||
&& entityPersister.isNullableTable( i ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int executeInsert(
|
||||
String targetTableExpression,
|
||||
NamedTableReference targetTableReference,
|
||||
Expression targetTableKeyExpression,
|
||||
Supplier<Consumer<SelectableConsumer>> tableKeyColumnVisitationSupplier,
|
||||
QuerySpec idTableSubQuery,
|
||||
List<Assignment> assignments,
|
||||
SqlAstTranslatorFactory sqlAstTranslatorFactory,
|
||||
JdbcMutationExecutor jdbcMutationExecutor,
|
||||
ExecutionContext executionContext) {
|
||||
|
||||
// Execute a query in the form -
|
||||
//
|
||||
// insert into <target> (...)
|
||||
// select ...
|
||||
// from <id-table> temptable_
|
||||
// where not exists (
|
||||
// select 1
|
||||
// from <target> dml_
|
||||
// where dml_.<key> = temptable_.<key>
|
||||
// )
|
||||
|
||||
// Create a new QuerySpec for the "insert source" select query. This
|
||||
// is mostly a copy of the incoming `idTableSubQuery` along with the
|
||||
// NOT-EXISTS predicate
|
||||
final QuerySpec insertSourceSelectQuerySpec = makeInsertSourceSelectQuerySpec( idTableSubQuery );
|
||||
|
||||
// create the `select 1 ...` sub-query and apply the not-exists predicate
|
||||
final QuerySpec existsSubQuerySpec = createExistsSubQuerySpec( targetTableExpression, tableKeyColumnVisitationSupplier, idTableSubQuery );
|
||||
insertSourceSelectQuerySpec.applyPredicate(
|
||||
new ExistsPredicate(
|
||||
existsSubQuerySpec,
|
||||
true,
|
||||
sessionFactory.getTypeConfiguration().getBasicTypeForJavaType( Boolean.class )
|
||||
)
|
||||
);
|
||||
|
||||
// Collect the target column references from the key expressions
|
||||
final List<ColumnReference> targetColumnReferences = new ArrayList<>();
|
||||
if ( targetTableKeyExpression instanceof SqlTuple ) {
|
||||
//noinspection unchecked
|
||||
targetColumnReferences.addAll( (Collection<? extends ColumnReference>) ( (SqlTuple) targetTableKeyExpression ).getExpressions() );
|
||||
}
|
||||
else {
|
||||
targetColumnReferences.add( (ColumnReference) targetTableKeyExpression );
|
||||
}
|
||||
|
||||
// And transform assignments to target column references and selections
|
||||
for ( Assignment assignment : assignments ) {
|
||||
targetColumnReferences.addAll( assignment.getAssignable().getColumnReferences() );
|
||||
insertSourceSelectQuerySpec.getSelectClause().addSqlSelection(
|
||||
new SqlSelectionImpl( 0, -1, assignment.getAssignedValue() )
|
||||
);
|
||||
}
|
||||
|
||||
final InsertSelectStatement insertSqlAst = new InsertSelectStatement( targetTableReference );
|
||||
insertSqlAst.addTargetColumnReferences( targetColumnReferences.toArray( new ColumnReference[0] ) );
|
||||
insertSqlAst.setSourceSelectStatement( insertSourceSelectQuerySpec );
|
||||
|
||||
final JdbcOperationQueryInsert jdbcInsert = sqlAstTranslatorFactory
|
||||
.buildInsertTranslator( sessionFactory, insertSqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
return jdbcMutationExecutor.execute(
|
||||
jdbcInsert,
|
||||
jdbcParameterBindings,
|
||||
sql -> executionContext.getSession()
|
||||
.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( sql ),
|
||||
(integer, preparedStatement) -> {
|
||||
},
|
||||
executionContext
|
||||
);
|
||||
}
|
||||
|
||||
private QuerySpec createExistsSubQuerySpec(String targetTableExpression, Supplier<Consumer<SelectableConsumer>> tableKeyColumnVisitationSupplier, QuerySpec idTableSubQuery) {
|
||||
final NamedTableReference existsTableReference = new NamedTableReference(
|
||||
targetTableExpression,
|
||||
"dml_"
|
||||
);
|
||||
|
||||
// Prepare a not exists sub-query to avoid violating constraints
|
||||
final QuerySpec existsSubQuerySpec = new QuerySpec( false );
|
||||
existsSubQuerySpec.getSelectClause().addSqlSelection(
|
||||
new SqlSelectionImpl(
|
||||
-1,
|
||||
0,
|
||||
new QueryLiteral<>(
|
||||
1,
|
||||
sessionFactory.getTypeConfiguration().getBasicTypeForJavaType( Integer.class )
|
||||
)
|
||||
)
|
||||
);
|
||||
existsSubQuerySpec.getFromClause().addRoot( new TableGroupImpl(
|
||||
null,
|
||||
null,
|
||||
existsTableReference,
|
||||
entityDescriptor
|
||||
) );
|
||||
|
||||
final TableKeyExpressionCollector existsKeyColumnCollector = new TableKeyExpressionCollector( entityDescriptor );
|
||||
tableKeyColumnVisitationSupplier.get().accept( (columnIndex, selection) -> {
|
||||
assert selection.getContainingTableExpression().equals( targetTableExpression );
|
||||
existsKeyColumnCollector.apply( new ColumnReference( existsTableReference, selection ) );
|
||||
} );
|
||||
existsSubQuerySpec.applyPredicate(
|
||||
new ComparisonPredicate(
|
||||
existsKeyColumnCollector.buildKeyExpression(),
|
||||
ComparisonOperator.EQUAL,
|
||||
asExpression( idTableSubQuery.getSelectClause())
|
||||
)
|
||||
);
|
||||
return existsSubQuerySpec;
|
||||
}
|
||||
|
||||
private static QuerySpec makeInsertSourceSelectQuerySpec(QuerySpec idTableSubQuery) {
|
||||
final QuerySpec idTableQuerySpec = new QuerySpec( true );
|
||||
for ( TableGroup root : idTableSubQuery.getFromClause().getRoots() ) {
|
||||
idTableQuerySpec.getFromClause().addRoot( root );
|
||||
}
|
||||
for ( SqlSelection sqlSelection : idTableSubQuery.getSelectClause().getSqlSelections() ) {
|
||||
idTableQuerySpec.getSelectClause().addSqlSelection( sqlSelection );
|
||||
}
|
||||
idTableQuerySpec.applyPredicate( idTableSubQuery.getWhereClauseRestrictions() );
|
||||
return idTableQuerySpec;
|
||||
}
|
||||
|
||||
private int executeUpdate(QuerySpec idTableSubQuery, ExecutionContext executionContext, List<Assignment> assignments, NamedTableReference dmlTableReference, SqlAstTranslatorFactory sqlAstTranslatorFactory, JdbcMutationExecutor jdbcMutationExecutor, Expression keyExpression) {
|
||||
final UpdateStatement sqlAst = new UpdateStatement(
|
||||
dmlTableReference,
|
||||
assignments,
|
||||
idTableSubQueryPredicate
|
||||
new InSubQueryPredicate( keyExpression, idTableSubQuery, false )
|
||||
);
|
||||
|
||||
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
final JdbcOperationQueryUpdate jdbcUpdate = sqlAstTranslatorFactory
|
||||
.buildUpdateTranslator( sessionFactory, sqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
final int updateCount = jdbcServices.getJdbcMutationExecutor().execute(
|
||||
final int updateCount = jdbcMutationExecutor.execute(
|
||||
jdbcUpdate,
|
||||
jdbcParameterBindings,
|
||||
sql -> executionContext.getSession()
|
||||
|
@ -299,129 +445,20 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
|
|||
},
|
||||
executionContext
|
||||
);
|
||||
return updateCount;
|
||||
}
|
||||
|
||||
if ( updateCount == expectedUpdateCount ) {
|
||||
// We are done when the update count matches
|
||||
return;
|
||||
}
|
||||
// Otherwise we have to check if the table is nullable, and if so, insert into that table
|
||||
final AbstractEntityPersister entityPersister = (AbstractEntityPersister) entityDescriptor.getEntityPersister();
|
||||
boolean isNullable = false;
|
||||
for (int i = 0; i < entityPersister.getTableSpan(); i++) {
|
||||
if ( tableExpression.equals( entityPersister.getTableName( i ) ) && entityPersister.isNullableTable( i ) ) {
|
||||
isNullable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( isNullable ) {
|
||||
// Copy the subquery contents into a root query
|
||||
final QuerySpec querySpec = new QuerySpec( true );
|
||||
for ( TableGroup root : idTableSubQuery.getFromClause().getRoots() ) {
|
||||
querySpec.getFromClause().addRoot( root );
|
||||
}
|
||||
for ( SqlSelection sqlSelection : idTableSubQuery.getSelectClause().getSqlSelections() ) {
|
||||
querySpec.getSelectClause().addSqlSelection( sqlSelection );
|
||||
}
|
||||
querySpec.applyPredicate( idTableSubQuery.getWhereClauseRestrictions() );
|
||||
private Expression resolveMutatingTableKeyExpression(String tableExpression, Supplier<Consumer<SelectableConsumer>> tableKeyColumnVisitationSupplier) {
|
||||
final TableKeyExpressionCollector keyColumnCollector = new TableKeyExpressionCollector( entityDescriptor );
|
||||
|
||||
// Prepare a not exists sub-query to avoid violating constraints
|
||||
final QuerySpec existsQuerySpec = new QuerySpec( false );
|
||||
existsQuerySpec.getSelectClause().addSqlSelection(
|
||||
new SqlSelectionImpl(
|
||||
-1,
|
||||
0,
|
||||
new QueryLiteral<>(
|
||||
1,
|
||||
sessionFactory.getTypeConfiguration().getBasicTypeForJavaType( Integer.class )
|
||||
)
|
||||
)
|
||||
);
|
||||
final NamedTableReference existsTableReference = new NamedTableReference(
|
||||
tableExpression,
|
||||
"dml_"
|
||||
);
|
||||
existsQuerySpec.getFromClause().addRoot(
|
||||
new TableGroupImpl(
|
||||
null,
|
||||
null,
|
||||
existsTableReference,
|
||||
entityPersister
|
||||
)
|
||||
);
|
||||
tableKeyColumnVisitationSupplier.get().accept(
|
||||
(columnIndex, selection) -> {
|
||||
assert selection.getContainingTableExpression().equals( tableExpression );
|
||||
keyColumnCollector.apply( new ColumnReference( (String) null, selection ) );
|
||||
}
|
||||
);
|
||||
|
||||
final TableKeyExpressionCollector existsKeyColumnCollector = new TableKeyExpressionCollector( entityDescriptor );
|
||||
tableKeyColumnVisitationSupplier.get().accept(
|
||||
(columnIndex, selection) -> {
|
||||
assert selection.getContainingTableExpression().equals( tableExpression );
|
||||
existsKeyColumnCollector.apply(
|
||||
new ColumnReference(
|
||||
existsTableReference,
|
||||
selection
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
existsQuerySpec.applyPredicate(
|
||||
new ComparisonPredicate(
|
||||
existsKeyColumnCollector.buildKeyExpression(),
|
||||
ComparisonOperator.EQUAL,
|
||||
asExpression(idTableSubQuery.getSelectClause())
|
||||
)
|
||||
);
|
||||
|
||||
querySpec.applyPredicate(
|
||||
new ExistsPredicate(
|
||||
existsQuerySpec,
|
||||
true,
|
||||
sessionFactory.getTypeConfiguration().getBasicTypeForJavaType( Boolean.class )
|
||||
)
|
||||
);
|
||||
|
||||
// Collect the target column references from the key expressions
|
||||
final List<ColumnReference> targetColumnReferences = new ArrayList<>();
|
||||
if ( keyExpression instanceof SqlTuple ) {
|
||||
//noinspection unchecked
|
||||
targetColumnReferences.addAll( (Collection<? extends ColumnReference>) ( (SqlTuple) keyExpression ).getExpressions() );
|
||||
}
|
||||
else {
|
||||
targetColumnReferences.add( (ColumnReference) keyExpression );
|
||||
}
|
||||
// And transform assignments to target column references and selections
|
||||
for ( Assignment assignment : assignments ) {
|
||||
targetColumnReferences.addAll( assignment.getAssignable().getColumnReferences() );
|
||||
querySpec.getSelectClause().addSqlSelection(
|
||||
new SqlSelectionImpl(
|
||||
0,
|
||||
-1,
|
||||
assignment.getAssignedValue()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
final InsertSelectStatement insertSqlAst = new InsertSelectStatement(
|
||||
dmlTableReference
|
||||
);
|
||||
insertSqlAst.addTargetColumnReferences( targetColumnReferences.toArray( new ColumnReference[0] ) );
|
||||
insertSqlAst.setSourceSelectStatement( querySpec );
|
||||
|
||||
final JdbcOperationQueryInsert jdbcInsert = jdbcServices.getJdbcEnvironment()
|
||||
.getSqlAstTranslatorFactory()
|
||||
.buildInsertTranslator( sessionFactory, insertSqlAst )
|
||||
.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
|
||||
|
||||
final int insertCount = jdbcServices.getJdbcMutationExecutor().execute(
|
||||
jdbcInsert,
|
||||
jdbcParameterBindings,
|
||||
sql -> executionContext.getSession()
|
||||
.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( sql ),
|
||||
(integer, preparedStatement) -> {
|
||||
},
|
||||
executionContext
|
||||
);
|
||||
assert insertCount + updateCount == expectedUpdateCount;
|
||||
}
|
||||
return keyColumnCollector.buildKeyExpression();
|
||||
}
|
||||
|
||||
private Expression asExpression(SelectClause selectClause) {
|
||||
|
|
|
@ -129,10 +129,6 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker<Obj
|
|||
return serviceRegistry;
|
||||
}
|
||||
|
||||
public Object visitStatement(SqmStatement<?> sqmStatement) {
|
||||
return sqmStatement.accept( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitSelectStatement(SqmSelectStatement<?> statement) {
|
||||
visitCteContainer( statement );
|
||||
|
|
|
@ -284,7 +284,6 @@ import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
|||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlAstProcessingState;
|
||||
import org.hibernate.sql.ast.spi.SqlAstQueryPartProcessingState;
|
||||
import org.hibernate.sql.ast.spi.SqlAstTreeHelper;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||
|
@ -417,6 +416,7 @@ import static org.hibernate.query.sqm.TemporalUnit.NANOSECOND;
|
|||
import static org.hibernate.query.sqm.TemporalUnit.NATIVE;
|
||||
import static org.hibernate.query.sqm.TemporalUnit.SECOND;
|
||||
import static org.hibernate.query.sqm.UnaryArithmeticOperator.UNARY_MINUS;
|
||||
import static org.hibernate.sql.ast.spi.SqlAstTreeHelper.combinePredicates;
|
||||
import static org.hibernate.type.spi.TypeConfiguration.isDuration;
|
||||
|
||||
/**
|
||||
|
@ -747,7 +747,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
public Stack<Clause> getCurrentClauseStack() {
|
||||
return currentClauseStack;
|
||||
}
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Statements
|
||||
|
||||
@Override
|
||||
|
@ -765,10 +767,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement visitStatement(SqmStatement<?> sqmStatement) {
|
||||
return (Statement) sqmStatement.accept( this );
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Update statement
|
||||
|
@ -804,9 +802,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
rootPath,
|
||||
sqmStatement.getRoot().getAlias(),
|
||||
() -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
|
||||
this,
|
||||
getCreationContext()
|
||||
null,
|
||||
() -> predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
this
|
||||
);
|
||||
|
||||
if ( ! rootTableGroup.getTableReferenceJoins().isEmpty() ) {
|
||||
|
@ -841,7 +839,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
cteContainer,
|
||||
(NamedTableReference) rootTableGroup.getPrimaryTableReference(),
|
||||
assignments,
|
||||
SqlAstTreeHelper.combinePredicates( suppliedPredicate, additionalRestrictions ),
|
||||
combinePredicates( suppliedPredicate, additionalRestrictions ),
|
||||
Collections.emptyList()
|
||||
);
|
||||
}
|
||||
|
@ -1073,10 +1071,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
rootPath,
|
||||
statement.getRoot().getAlias(),
|
||||
() -> predicate -> additionalRestrictions
|
||||
= SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
|
||||
this,
|
||||
getCreationContext()
|
||||
null,
|
||||
() -> (predicate) -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
this
|
||||
);
|
||||
getFromClauseAccess().registerTableGroup( rootPath, rootTableGroup );
|
||||
|
||||
|
@ -1102,7 +1099,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
return new DeleteStatement(
|
||||
cteContainer,
|
||||
(NamedTableReference) rootTableGroup.getPrimaryTableReference(),
|
||||
SqlAstTreeHelper.combinePredicates( suppliedPredicate, additionalRestrictions ),
|
||||
combinePredicates( suppliedPredicate, additionalRestrictions ),
|
||||
Collections.emptyList()
|
||||
);
|
||||
}
|
||||
|
@ -1153,10 +1150,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
rootPath,
|
||||
sqmStatement.getTarget().getExplicitAlias(),
|
||||
() -> predicate -> additionalRestrictions
|
||||
= SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
|
||||
this,
|
||||
getCreationContext()
|
||||
null,
|
||||
() -> predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
this
|
||||
);
|
||||
|
||||
getFromClauseAccess().registerTableGroup( rootPath, rootTableGroup );
|
||||
|
@ -1253,10 +1249,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
rootPath,
|
||||
sqmStatement.getTarget().getExplicitAlias(),
|
||||
() -> predicate -> additionalRestrictions
|
||||
= SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
|
||||
this,
|
||||
getCreationContext()
|
||||
null,
|
||||
() -> predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
this
|
||||
);
|
||||
|
||||
if ( !rootTableGroup.getTableReferenceJoins().isEmpty()
|
||||
|
@ -2467,7 +2462,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
currentClauseStack.push( Clause.WHERE );
|
||||
inferrableTypeAccessStack.push( () -> null );
|
||||
try {
|
||||
return SqlAstTreeHelper.combinePredicates(
|
||||
return combinePredicates(
|
||||
(Predicate) sqmPredicate.accept( this ),
|
||||
consumeConjunctTreatTypeRestrictions()
|
||||
);
|
||||
|
@ -2486,7 +2481,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
currentClauseStack.push( Clause.HAVING );
|
||||
inferrableTypeAccessStack.push( () -> null );
|
||||
try {
|
||||
return SqlAstTreeHelper.combinePredicates(
|
||||
return combinePredicates(
|
||||
(Predicate) sqmPredicate.accept( this ),
|
||||
consumeConjunctTreatTypeRestrictions()
|
||||
);
|
||||
|
@ -2602,10 +2597,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
parentTableGroup,
|
||||
sqlAliasBase,
|
||||
currentQuerySpec,
|
||||
predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions,
|
||||
predicate
|
||||
),
|
||||
predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
sessionFactory
|
||||
);
|
||||
final TableGroup elementTableGroup = pluralTableGroup.getElementTableGroup();
|
||||
|
@ -2614,10 +2606,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
elementTableGroup,
|
||||
sqlAliasBase,
|
||||
currentQuerySpec,
|
||||
predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions,
|
||||
predicate
|
||||
),
|
||||
predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
sessionFactory
|
||||
);
|
||||
final TableGroupJoin tableGroupJoin = new TableGroupJoin(
|
||||
|
@ -2633,10 +2622,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
indexTableGroup,
|
||||
sqlAliasBase,
|
||||
currentQuerySpec,
|
||||
predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions,
|
||||
predicate
|
||||
),
|
||||
predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
sessionFactory
|
||||
);
|
||||
final TableGroupJoin tableGroupJoin = new TableGroupJoin(
|
||||
|
@ -2653,10 +2639,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
parentTableGroup,
|
||||
sqlAliasBase,
|
||||
currentQuerySpec,
|
||||
predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions,
|
||||
predicate
|
||||
),
|
||||
predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
sessionFactory
|
||||
);
|
||||
}
|
||||
|
@ -2682,16 +2665,16 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
sqmRoot.getNavigablePath(),
|
||||
sqmRoot.getExplicitAlias(),
|
||||
null,
|
||||
() -> predicate -> {},
|
||||
this,
|
||||
creationContext
|
||||
this
|
||||
);
|
||||
final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
|
||||
final NavigablePath navigablePath = sqmRoot.getNavigablePath().append( identifierMapping.getNavigableRole().getNavigableName() );
|
||||
final int jdbcTypeCount = identifierMapping.getJdbcTypeCount();
|
||||
if ( jdbcTypeCount == 1 ) {
|
||||
identifierMapping.forEachSelectable(
|
||||
(index, selectable) -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
(index, selectable) -> additionalRestrictions = combinePredicates(
|
||||
additionalRestrictions,
|
||||
new ComparisonPredicate(
|
||||
new ColumnReference(
|
||||
|
@ -2726,7 +2709,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
);
|
||||
}
|
||||
);
|
||||
additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions = combinePredicates(
|
||||
additionalRestrictions,
|
||||
new ComparisonPredicate(
|
||||
new SqlTuple( lhs, identifierMapping ),
|
||||
|
@ -2798,12 +2781,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
sqmRoot.getNavigablePath(),
|
||||
sqmRoot.getExplicitAlias(),
|
||||
() -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions,
|
||||
predicate
|
||||
),
|
||||
this,
|
||||
creationContext
|
||||
null,
|
||||
() -> predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
this
|
||||
);
|
||||
|
||||
entityDescriptor.applyBaseRestrictions(
|
||||
|
@ -3069,6 +3049,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
sqmJoinNavigablePath,
|
||||
ownerTableGroup,
|
||||
sqmJoin.getExplicitAlias(),
|
||||
null,
|
||||
sqmJoinType.getCorrespondingSqlJoinType(),
|
||||
sqmJoin.isFetched(),
|
||||
sqmJoin.getJoinPredicate() != null,
|
||||
|
@ -3093,6 +3074,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
sqmJoinNavigablePath,
|
||||
ownerTableGroup,
|
||||
sqmJoin.getExplicitAlias(),
|
||||
null,
|
||||
sqmJoinType.getCorrespondingSqlJoinType(),
|
||||
sqmJoin.isFetched(),
|
||||
sqmJoin.getJoinPredicate() != null,
|
||||
|
@ -3113,7 +3095,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
|
||||
getFromClauseIndex().register( sqmJoin, joinedTableGroup );
|
||||
registerPluralTableGroupParts( joinedTableGroup );
|
||||
// For joins we also need to register the table groups for the treats
|
||||
// For joins, we also need to register the table groups for the treats
|
||||
if ( joinedTableGroup instanceof PluralTableGroup ) {
|
||||
final PluralTableGroup pluralTableGroup = (PluralTableGroup) joinedTableGroup;
|
||||
for ( SqmFrom<?, ?> sqmTreat : sqmJoin.getSqmTreats() ) {
|
||||
|
@ -3165,12 +3147,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
sqmJoin.getNavigablePath(),
|
||||
sqmJoin.getExplicitAlias(),
|
||||
() -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions,
|
||||
predicate
|
||||
),
|
||||
this,
|
||||
getCreationContext()
|
||||
null,
|
||||
() -> predicate -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
this
|
||||
);
|
||||
|
||||
final TableGroupJoin tableGroupJoin = new TableGroupJoin(
|
||||
|
@ -3197,12 +3176,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
correspondingSqlJoinType == SqlAstJoinType.INNER || correspondingSqlJoinType == SqlAstJoinType.CROSS,
|
||||
sqmJoin.getNavigablePath(),
|
||||
sqmJoin.getExplicitAlias(),
|
||||
() -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(
|
||||
additionalRestrictions,
|
||||
predicate
|
||||
),
|
||||
this,
|
||||
getCreationContext()
|
||||
null,
|
||||
() -> (predicate) -> additionalRestrictions = combinePredicates( additionalRestrictions, predicate ),
|
||||
this
|
||||
);
|
||||
getFromClauseIndex().register( sqmJoin, tableGroup );
|
||||
|
||||
|
@ -3521,6 +3497,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
actualParentTableGroup,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
querySpec::applyPredicate,
|
||||
this
|
||||
|
@ -3542,6 +3519,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
actualParentTableGroup,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
this
|
||||
|
@ -4264,9 +4242,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
pluralPath.getNavigablePath(),
|
||||
null,
|
||||
null,
|
||||
() -> subQuerySpec::applyPredicate,
|
||||
this,
|
||||
creationContext
|
||||
this
|
||||
);
|
||||
|
||||
pluralAttributeMapping.applyBaseRestrictions(
|
||||
|
@ -4300,8 +4278,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(
|
||||
parentTableGroup,
|
||||
tableGroup,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
this
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -4333,13 +4310,11 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
mapNavigablePath,
|
||||
parentTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
false,
|
||||
false,
|
||||
sqlAliasBaseManager,
|
||||
getSqlExpressionResolver(),
|
||||
this,
|
||||
creationContext
|
||||
this
|
||||
);
|
||||
|
||||
parentTableGroup.addTableGroupJoin( tableGroupJoin );
|
||||
|
@ -4411,9 +4386,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
pluralPartPath.getNavigablePath(),
|
||||
null,
|
||||
null,
|
||||
() -> subQuerySpec::applyPredicate,
|
||||
this,
|
||||
creationContext
|
||||
this
|
||||
);
|
||||
|
||||
pluralAttributeMapping.applyBaseRestrictions(
|
||||
|
@ -4487,8 +4462,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(
|
||||
parentFromClauseAccess.findTableGroup( parent ),
|
||||
tableGroup,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
this
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -4555,9 +4529,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
pluralPartPath.getNavigablePath(),
|
||||
null,
|
||||
null,
|
||||
() -> subQuerySpec::applyPredicate,
|
||||
this,
|
||||
creationContext
|
||||
this
|
||||
);
|
||||
|
||||
pluralAttributeMapping.applyBaseRestrictions(
|
||||
|
@ -4677,8 +4651,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralPartPath.getPluralDomainPath().getNavigablePath().getParent()
|
||||
),
|
||||
tableGroup,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
this
|
||||
)
|
||||
);
|
||||
final Set<String> compatibleTableExpressions;
|
||||
|
@ -4856,7 +4829,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
}
|
||||
Predicate predicate = null;
|
||||
for ( Map.Entry<SqmPath<?>, Set<String>> entry : conjunctTreatUsages.entrySet() ) {
|
||||
predicate = SqlAstTreeHelper.combinePredicates(
|
||||
predicate = combinePredicates(
|
||||
predicate,
|
||||
createTreatTypeRestriction( entry.getKey(), entry.getValue() )
|
||||
);
|
||||
|
@ -6575,7 +6548,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
}
|
||||
conjunctTreatUsages.clear();
|
||||
final Predicate result = (Predicate) predicate.accept( this );
|
||||
final Predicate finalPredicate = SqlAstTreeHelper.combinePredicates(
|
||||
final Predicate finalPredicate = combinePredicates(
|
||||
result,
|
||||
consumeConjunctTreatTypeRestrictions()
|
||||
);
|
||||
|
@ -6662,7 +6635,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
if ( conjunctTreatUsages != null ) {
|
||||
disjunction.getPredicates().set(
|
||||
i,
|
||||
SqlAstTreeHelper.combinePredicates(
|
||||
combinePredicates(
|
||||
consumeConjunctTreatTypeRestrictions( conjunctTreatUsages ),
|
||||
disjunction.getPredicates().get( i )
|
||||
)
|
||||
|
@ -6706,9 +6679,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
true,
|
||||
pluralPath.getNavigablePath(),
|
||||
null,
|
||||
null,
|
||||
() -> subQuerySpec::applyPredicate,
|
||||
this,
|
||||
creationContext
|
||||
this
|
||||
);
|
||||
|
||||
pluralAttributeMapping.applyBaseRestrictions(
|
||||
|
@ -6734,8 +6707,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(
|
||||
parentFromClauseAccess.findTableGroup( pluralPath.getNavigablePath().getParent() ),
|
||||
tableGroup,
|
||||
getSqlExpressionResolver(),
|
||||
creationContext
|
||||
this
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -6833,13 +6805,11 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
pluralPathNavPath,
|
||||
tableGroup,
|
||||
sqmPluralPath.getExplicitAlias(),
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
false,
|
||||
false,
|
||||
sqlAliasBaseManager,
|
||||
subQueryState,
|
||||
this,
|
||||
creationContext
|
||||
this
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -7279,6 +7249,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
lhs,
|
||||
alias,
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
BaseSqmToSqlAstConverter.this
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.sql.ast.spi;
|
||||
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupProducer;
|
||||
|
||||
/**
|
||||
* A generator for new incremental SQL aliases based on a stem
|
||||
*
|
||||
|
@ -21,4 +23,24 @@ public interface SqlAliasBase {
|
|||
* Generates a new alias based on the stem
|
||||
*/
|
||||
String generateNewAlias();
|
||||
|
||||
static SqlAliasBase from(
|
||||
SqlAliasBase explicitBase,
|
||||
String explicitSourceAlias,
|
||||
TableGroupProducer producer,
|
||||
SqlAliasBaseGenerator generator) {
|
||||
if ( explicitBase != null ) {
|
||||
return explicitBase;
|
||||
}
|
||||
|
||||
final String baseName;
|
||||
// if ( explicitSourceAlias != null && !Character.isDigit( explicitSourceAlias.charAt( 0 ) ) ) {
|
||||
// baseName = explicitSourceAlias;
|
||||
// }
|
||||
// else {
|
||||
baseName = producer.getSqlAliasStem();
|
||||
// }
|
||||
|
||||
return generator.createSqlAliasBase( baseName );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,11 +10,9 @@ import java.util.function.Consumer;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
|
||||
/**
|
||||
|
@ -26,22 +24,19 @@ import org.hibernate.sql.ast.tree.predicate.Predicate;
|
|||
public interface RootTableGroupProducer extends TableGroupProducer {
|
||||
/**
|
||||
* Create a root TableGroup as defined by this producer
|
||||
*
|
||||
* @param canUseInnerJoins Whether inner joins can be used when creating {@linkplain TableReference table-references} within this group
|
||||
* @param navigablePath The overall NavigablePath for the root
|
||||
* @param explicitSourceAlias The alias, if one, explicitly provided by the application for this root
|
||||
* @param explicitSqlAliasBase A specific SqlAliasBase to use. May be {@code null} indicating one should be created using the {@linkplain SqlAliasBaseGenerator} from {@code creationState}
|
||||
* @param additionalPredicateCollectorAccess Collector for additional predicates associated with this producer
|
||||
* @param creationState The creation state
|
||||
*/
|
||||
TableGroup createRootTableGroup(
|
||||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAstCreationState creationState,
|
||||
SqlAstCreationContext creationContext);
|
||||
|
||||
TableGroup createRootTableGroup(
|
||||
boolean canUseInnerJoins,
|
||||
NavigablePath navigablePath,
|
||||
String explicitSourceAlias,
|
||||
Supplier<Consumer<Predicate>> additionalPredicateCollectorAccess,
|
||||
SqlAliasBase sqlAliasBase,
|
||||
SqlExpressionResolver expressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationState creationState);
|
||||
}
|
||||
|
|
|
@ -10,11 +10,10 @@ import java.util.function.Consumer;
|
|||
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBase;
|
||||
import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
|
||||
/**
|
||||
|
@ -31,98 +30,50 @@ public interface TableGroupJoinProducer extends TableGroupProducer {
|
|||
boolean isSimpleJoinPredicate(Predicate predicate);
|
||||
|
||||
/**
|
||||
* Create a TableGroupJoin as defined for this producer
|
||||
* Create a TableGroupJoin.
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
* When addsPredicate is <code>true</code>, the SQM join for the attribute contains an explicit <code>ON</code> clause,
|
||||
* and is <code>false</code> otherwise.
|
||||
*/
|
||||
default TableGroupJoin createTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAstCreationState creationState) {
|
||||
return createTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
fetched,
|
||||
addsPredicate,
|
||||
creationState.getSqlAliasBaseGenerator(),
|
||||
creationState.getSqlExpressionResolver(),
|
||||
creationState.getFromClauseAccess(),
|
||||
creationState.getCreationContext()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a TableGroupJoin as defined for this producer
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
* When addsPredicate is <code>true</code>, the SQM join for the attribute contains an explicit <code>ON</code> clause,
|
||||
* and is <code>false</code> otherwise.
|
||||
* @param navigablePath The NavigablePath to the join
|
||||
* @param lhs The join's (L)eft-(H)and (S)ide
|
||||
* @param explicitSqlAliasBase A specific SqlAliasBase to use. May be {@code null} indicating one should be created using the {@linkplain SqlAliasBaseGenerator} from {@code creationState}
|
||||
* @param sqlAstJoinType An explicit join-type. May be null to signal that the join is for an implicit path.
|
||||
* @param addsPredicate Indicates there are explicit, additional predicates (from an SQM tree ON/WITH clause)
|
||||
*/
|
||||
TableGroupJoin createTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
boolean addsPredicate,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationState creationState);
|
||||
|
||||
/**
|
||||
* Create a TableGroupJoin as defined for this producer, but as root TableGroup.
|
||||
* The main purpose of this is for correlating an association in a subquery
|
||||
* i.e. `... alias where exists (select 1 from SomeEntity e where alias.association.attr = 1)`.
|
||||
* Create the "join", but return a TableGroup. Intended for creating sub-query
|
||||
* correlations. E.g., given
|
||||
* <pre>
|
||||
* from SomeEntity e
|
||||
* where exists (
|
||||
* select 1
|
||||
* from AnotherEntity a
|
||||
* where e.association.attr = 1
|
||||
* )
|
||||
* </pre>
|
||||
* We call this for the `e.association` path.
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
*/
|
||||
default TableGroup createRootTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAstCreationState creationState) {
|
||||
return createRootTableGroupJoin(
|
||||
navigablePath,
|
||||
lhs,
|
||||
explicitSourceAlias,
|
||||
sqlAstJoinType,
|
||||
fetched,
|
||||
predicateConsumer,
|
||||
creationState.getSqlAliasBaseGenerator(),
|
||||
creationState.getSqlExpressionResolver(),
|
||||
creationState.getFromClauseAccess(),
|
||||
creationState.getCreationContext()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a TableGroupJoin as defined for this producer, but as root TableGroup.
|
||||
* The main purpose of this is for correlating an association in a subquery
|
||||
* i.e. `... alias where exists (select 1 from SomeEntity e where alias.association.attr = 1)`.
|
||||
*
|
||||
* The sqlAstJoinType may be null to signal that the join is for an implicit path.
|
||||
* @param navigablePath The NavigablePath to the join
|
||||
* @param lhs The join's (L)eft-(H)and (S)ide
|
||||
* @param explicitSqlAliasBase A specific SqlAliasBase to use. May be {@code null} indicating one should be created using the {@linkplain SqlAliasBaseGenerator} from {@code creationState}
|
||||
* @param sqlAstJoinType An explicit join-type. May be null to signal that the join is for an implicit path.
|
||||
* @param predicateConsumer Consumer for additional predicates from the producer's mapping.
|
||||
*/
|
||||
TableGroup createRootTableGroupJoin(
|
||||
NavigablePath navigablePath,
|
||||
TableGroup lhs,
|
||||
String explicitSourceAlias,
|
||||
SqlAliasBase explicitSqlAliasBase,
|
||||
SqlAstJoinType sqlAstJoinType,
|
||||
boolean fetched,
|
||||
Consumer<Predicate> predicateConsumer,
|
||||
SqlAliasBaseGenerator aliasBaseGenerator,
|
||||
SqlExpressionResolver sqlExpressionResolver,
|
||||
FromClauseAccess fromClauseAccess,
|
||||
SqlAstCreationContext creationContext);
|
||||
SqlAstCreationState creationState);
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements
|
|||
getNavigablePath(),
|
||||
lhsTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.sql.results.graph.embeddable.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||
|
@ -34,7 +32,6 @@ import org.hibernate.sql.results.graph.embeddable.EmbeddableResult;
|
|||
import org.hibernate.sql.results.graph.embeddable.EmbeddableResultGraphNode;
|
||||
import org.hibernate.sql.results.graph.internal.ImmutableFetchList;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
import org.hibernate.type.descriptor.jdbc.AggregateJdbcType;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
|
@ -79,6 +76,7 @@ public class AggregateEmbeddableResultImpl<T> extends AbstractFetchParent implem
|
|||
navigablePath,
|
||||
tg,
|
||||
resultVariable,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
|
|
@ -60,6 +60,7 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
|
|||
getNavigablePath(),
|
||||
lhsTableGroup,
|
||||
null,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
|
|
@ -6,10 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.sql.results.graph.embeddable.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
|
@ -61,6 +59,7 @@ public class EmbeddableResultImpl<T> extends AbstractFetchParent implements Embe
|
|||
navigablePath,
|
||||
tableGroup,
|
||||
resultVariable,
|
||||
null,
|
||||
SqlAstJoinType.INNER,
|
||||
true,
|
||||
false,
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test;
|
|||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||
import jakarta.persistence.SecondaryTable;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
|
@ -53,9 +54,9 @@ public class SecondaryTableTests {
|
|||
}
|
||||
|
||||
@Entity( name = "SimpleEntityWithSecondaryTables" )
|
||||
@Table( name = "simple_w_secondary_tables0" )
|
||||
@SecondaryTable( name = "simple_w_secondary_tables1" )
|
||||
@SecondaryTable( name = "simple_w_secondary_tables2" )
|
||||
@Table( name = "root_table" )
|
||||
@SecondaryTable( name = "secondary_table1", pkJoinColumns = @PrimaryKeyJoinColumn( name = "s1_id" ) )
|
||||
@SecondaryTable( name = "secondary_table2", pkJoinColumns = @PrimaryKeyJoinColumn( name = "s2_id" ) )
|
||||
public static class SimpleEntityWithSecondaryTables {
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
@ -89,7 +90,7 @@ public class SecondaryTableTests {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
@Column( table = "simple_w_secondary_tables1" )
|
||||
@Column( table = "secondary_table1" )
|
||||
public Date getDob() {
|
||||
return dob;
|
||||
}
|
||||
|
@ -98,7 +99,7 @@ public class SecondaryTableTests {
|
|||
this.dob = dob;
|
||||
}
|
||||
|
||||
@Column( table = "simple_w_secondary_tables2" )
|
||||
@Column( table = "secondary_table2" )
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue