diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java index 71373681ae..8219209d57 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ForeignKeyDescriptor.java @@ -19,6 +19,7 @@ import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; +import org.hibernate.sql.results.graph.FetchParent; /** * Descriptor for foreign-keys @@ -81,7 +82,7 @@ public interface ForeignKeyDescriptor extends VirtualModelPart, ValueMapping { DomainResult createKeyDomainResult( NavigablePath navigablePath, TableGroup tableGroup, - DomainResultCreationState creationState); + FetchParent fetchParent, DomainResultCreationState creationState); /** * Create a DomainResult for the target-side of the fk @@ -89,18 +90,13 @@ public interface ForeignKeyDescriptor extends VirtualModelPart, ValueMapping { DomainResult createTargetDomainResult( NavigablePath navigablePath, TableGroup tableGroup, - DomainResultCreationState creationState); - - DomainResult createCollectionFetchDomainResult( - NavigablePath collectionPath, - TableGroup tableGroup, - DomainResultCreationState creationState); + FetchParent fetchParent, DomainResultCreationState creationState); DomainResult createDomainResult( NavigablePath navigablePath, TableGroup tableGroup, Nature side, - DomainResultCreationState creationState); + FetchParent fetchParent, DomainResultCreationState creationState); Predicate generateJoinPredicate( TableGroup targetSideTableGroup, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDiscriminatorMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDiscriminatorMapping.java index ba58452163..026d1bb76b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDiscriminatorMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDiscriminatorMapping.java @@ -130,7 +130,13 @@ public abstract class AbstractDiscriminatorMapping implements EntityDiscriminato TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) { - final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, getUnderlyingJdbcMappingType(), tableGroup, creationState.getSqlAstCreationState() ); + final SqlSelection sqlSelection = resolveSqlSelection( + navigablePath, + getUnderlyingJdbcMappingType(), + tableGroup, + null, + creationState.getSqlAstCreationState() + ); //noinspection unchecked return new BasicResult( @@ -146,11 +152,13 @@ public abstract class AbstractDiscriminatorMapping implements EntityDiscriminato NavigablePath navigablePath, JdbcMapping jdbcMappingToUse, TableGroup tableGroup, + FetchParent fetchParent, SqlAstCreationState creationState) { final SqlExpressionResolver expressionResolver = creationState.getSqlExpressionResolver(); return expressionResolver.resolveSqlSelection( resolveSqlExpression( navigablePath, jdbcMappingToUse, tableGroup, creationState ), jdbcMappingToUse.getJavaTypeDescriptor(), + fetchParent, creationState.getCreationContext().getSessionFactory().getTypeConfiguration() ); } @@ -170,7 +178,13 @@ public abstract class AbstractDiscriminatorMapping implements EntityDiscriminato assert tableGroup != null; - final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, getUnderlyingJdbcMappingType(), tableGroup, creationState.getSqlAstCreationState() ); + final SqlSelection sqlSelection = resolveSqlSelection( + fetchablePath, + getUnderlyingJdbcMappingType(), + tableGroup, + fetchParent, + creationState.getSqlAstCreationState() + ); return new BasicFetch<>( sqlSelection.getValuesArrayPosition(), @@ -188,7 +202,7 @@ public abstract class AbstractDiscriminatorMapping implements EntityDiscriminato NavigablePath navigablePath, TableGroup tableGroup, DomainResultCreationState creationState) { - resolveSqlSelection( navigablePath, getUnderlyingJdbcMappingType(), tableGroup, creationState.getSqlAstCreationState() ); + resolveSqlSelection( navigablePath, getUnderlyingJdbcMappingType(), tableGroup, null, creationState.getSqlAstCreationState() ); } @Override @@ -198,7 +212,7 @@ public abstract class AbstractDiscriminatorMapping implements EntityDiscriminato DomainResultCreationState creationState, BiConsumer selectionConsumer) { selectionConsumer.accept( - resolveSqlSelection( navigablePath, getUnderlyingJdbcMappingType(), tableGroup, creationState.getSqlAstCreationState() ), + resolveSqlSelection( navigablePath, getUnderlyingJdbcMappingType(), tableGroup, null, creationState.getSqlAstCreationState() ), getJdbcMapping() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java index 4ecf28089e..7a447355a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java @@ -274,6 +274,7 @@ public class AnyDiscriminatorPart implements BasicValuedModelPart, FetchOptions, final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( columnReference, jdbcMapping().getMappedJavaType(), + fetchParent, sessionFactory.getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java index 930c3bd942..8ef6bc2154 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java @@ -199,6 +199,7 @@ public class AnyKeyPart implements BasicValuedModelPart, FetchOptions { final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( columnReference, getJavaType(), + fetchParent, sessionFactory.getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java index 51f66d047b..9ee645e462 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java @@ -254,7 +254,7 @@ public class BasicAttributeMapping TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) { - final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, tableGroup, true, creationState ); + final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ); //noinspection unchecked return new BasicResult( @@ -270,6 +270,7 @@ public class BasicAttributeMapping NavigablePath navigablePath, TableGroup tableGroup, boolean allowFkOptimization, + FetchParent fetchParent, DomainResultCreationState creationState) { final SqlExpressionResolver expressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver(); final TableReference tableReference = tableGroup.resolveTableReference( @@ -291,6 +292,7 @@ public class BasicAttributeMapping ) ), valueConverter == null ? getMappedType().getMappedJavaType() : valueConverter.getRelationalJavaType(), + fetchParent, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration() ); } @@ -300,7 +302,7 @@ public class BasicAttributeMapping NavigablePath navigablePath, TableGroup tableGroup, DomainResultCreationState creationState) { - resolveSqlSelection( navigablePath, tableGroup, true, creationState ); + resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ); } @Override @@ -309,7 +311,7 @@ public class BasicAttributeMapping TableGroup tableGroup, DomainResultCreationState creationState, BiConsumer selectionConsumer) { - selectionConsumer.accept( resolveSqlSelection( navigablePath, tableGroup, true, creationState ), getJdbcMapping() ); + selectionConsumer.accept( resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ), getJdbcMapping() ); } @Override @@ -336,7 +338,7 @@ public class BasicAttributeMapping assert tableGroup != null; - final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, tableGroup, true, creationState ); + final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, tableGroup, true, fetchParent, creationState ); valuesArrayPosition = sqlSelection.getValuesArrayPosition(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java index 08e0826933..b7ecacfc06 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java @@ -215,7 +215,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) { - final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, tableGroup, true, creationState ); + final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ); return new BasicResult( sqlSelection.getValuesArrayPosition(), @@ -230,7 +230,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa NavigablePath navigablePath, TableGroup tableGroup, DomainResultCreationState creationState) { - resolveSqlSelection( navigablePath, tableGroup, true, creationState ); + resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ); } @Override @@ -240,7 +240,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa DomainResultCreationState creationState, BiConsumer selectionConsumer) { selectionConsumer.accept( - resolveSqlSelection( navigablePath, tableGroup, true, creationState ), + resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ), getJdbcMapping() ); } @@ -249,6 +249,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa NavigablePath navigablePath, TableGroup tableGroup, boolean allowFkOptimization, + FetchParent fetchParent, DomainResultCreationState creationState) { final SqlExpressionResolver expressionResolver = creationState.getSqlAstCreationState() .getSqlExpressionResolver(); @@ -285,6 +286,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa return expressionResolver.resolveSqlSelection( expression, idType.getExpressibleJavaType(), + fetchParent, sessionFactory.getTypeConfiguration() ); } @@ -383,7 +385,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa assert tableGroup != null; - final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, tableGroup, false, creationState ); + final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, tableGroup, false, fetchParent, creationState ); return new BasicFetch<>( sqlSelection.getValuesArrayPosition(), fetchParent, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java index 174373b655..d0ab4fd4c1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java @@ -151,7 +151,7 @@ public class BasicValuedCollectionPart TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) { - final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, tableGroup, true, creationState ); + final SqlSelection sqlSelection = resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ); //noinspection unchecked return new BasicResult( @@ -167,6 +167,7 @@ public class BasicValuedCollectionPart NavigablePath navigablePath, TableGroup tableGroup, boolean allowFkOptimization, + FetchParent fetchParent, DomainResultCreationState creationState) { final SqlExpressionResolver exprResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver(); final TableGroup targetTableGroup; @@ -197,6 +198,7 @@ public class BasicValuedCollectionPart ) ), getJavaType(), + fetchParent, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration() ); } @@ -204,7 +206,7 @@ public class BasicValuedCollectionPart @Override public void applySqlSelections( NavigablePath navigablePath, TableGroup tableGroup, DomainResultCreationState creationState) { - resolveSqlSelection( navigablePath, tableGroup, true, creationState ); + resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ); } @Override @@ -213,7 +215,7 @@ public class BasicValuedCollectionPart TableGroup tableGroup, DomainResultCreationState creationState, BiConsumer selectionConsumer) { - selectionConsumer.accept( resolveSqlSelection( navigablePath, tableGroup, true, creationState ), getJdbcMapping() ); + selectionConsumer.accept( resolveSqlSelection( navigablePath, tableGroup, true, null, creationState ), getJdbcMapping() ); } @Override @@ -263,7 +265,7 @@ public class BasicValuedCollectionPart final TableGroup tableGroup = creationState.getSqlAstCreationState() .getFromClauseAccess() .findTableGroup( parentNavigablePath ); - final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, tableGroup, true, creationState ); + final SqlSelection sqlSelection = resolveSqlSelection( fetchablePath, tableGroup, true, fetchParent, creationState ); return new BasicFetch<>( sqlSelection.getValuesArrayPosition(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java index 6ca7a9ab07..d1dec0473b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java @@ -231,6 +231,7 @@ public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierD ) ), type.getJavaTypeDescriptor(), + fetchParent, sessionFactory.getTypeConfiguration() ); @@ -271,6 +272,7 @@ public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierD ) ), type.getJavaTypeDescriptor(), + null, sessionFactory.getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java index 2eeb89fcc7..a8266072ec 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedForeignKeyDescriptor.java @@ -45,6 +45,7 @@ import org.hibernate.sql.ast.tree.predicate.Junction; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; +import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableForeignKeyResultImpl; import org.hibernate.type.descriptor.java.JavaType; @@ -187,6 +188,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { public DomainResult createKeyDomainResult( NavigablePath navigablePath, TableGroup tableGroup, + FetchParent fetchParent, DomainResultCreationState creationState) { return createDomainResult( navigablePath, @@ -194,6 +196,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { null, keyTable, keySide.getModelPart(), + fetchParent, creationState ); } @@ -202,6 +205,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { public DomainResult createTargetDomainResult( NavigablePath navigablePath, TableGroup tableGroup, + FetchParent fetchParent, DomainResultCreationState creationState) { assert tableGroup.getTableReference( navigablePath, targetTable ) != null; @@ -211,42 +215,17 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { null, targetTable, targetSide.getModelPart(), + fetchParent, creationState ); } - @Override - public DomainResult createCollectionFetchDomainResult( - NavigablePath collectionPath, - TableGroup tableGroup, - DomainResultCreationState creationState) { - if ( targetTable.equals( keyTable ) ) { - return createDomainResult( - collectionPath, - tableGroup, - null, - targetTable, - targetSide.getModelPart(), - creationState - ); - } - else { - return createDomainResult( - collectionPath, - tableGroup, - null, - keyTable, - keySide.getModelPart(), - creationState - ); - } - } - @Override public DomainResult createDomainResult( NavigablePath navigablePath, TableGroup tableGroup, Nature side, + FetchParent fetchParent, DomainResultCreationState creationState) { if ( side == Nature.KEY ) { return createDomainResult( @@ -255,6 +234,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { null, keyTable, keySide.getModelPart(), + fetchParent, creationState ); } @@ -265,6 +245,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { null, targetTable, targetSide.getModelPart(), + fetchParent, creationState ); } @@ -276,7 +257,15 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) { - return createDomainResult( navigablePath, tableGroup, resultVariable, keyTable, keySide.getModelPart(), creationState ); + return createDomainResult( + navigablePath, + tableGroup, + resultVariable, + keyTable, + keySide.getModelPart(), + null, + creationState + ); } @Override @@ -302,6 +291,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { String resultVariable, String columnContainingTable, EmbeddableValuedModelPart modelPart, + FetchParent fetchParent, DomainResultCreationState creationState) { final NavigablePath resultNavigablePath; if ( modelPart == keySide.getModelPart() ) { @@ -334,6 +324,7 @@ public class EmbeddedForeignKeyDescriptor implements ForeignKeyDescriptor { resultNavigablePath, modelPart, resultVariable, + fetchParent, creationState ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java index 97284b8e65..f6bd4026d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityRowIdMappingImpl.java @@ -106,6 +106,7 @@ public class EntityRowIdMappingImpl implements EntityRowIdMapping, SelectableMap ) ), rowIdType.getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java index e7a7a6e580..edfacece33 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EntityVersionMappingImpl.java @@ -38,7 +38,6 @@ import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.type.BasicType; -import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.VersionJavaType; /** @@ -228,6 +227,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti ) ), versionBasicType.getJdbcMapping().getJavaTypeDescriptor(), + fetchParent, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() ); @@ -302,6 +302,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti ) ), versionBasicType.getJdbcMapping().getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java index 77fb4146f3..f1e2cce3b7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java @@ -466,6 +466,7 @@ public class PluralAttributeMappingImpl final DomainResult collectionKeyDomainResult = getKeyDescriptor().createTargetDomainResult( fetchablePath, sqlAstCreationState.getFromClauseAccess().getTableGroup( fetchParent.getNavigablePath() ), + fetchParent, creationState ); @@ -517,6 +518,7 @@ public class PluralAttributeMappingImpl collectionKeyDomainResult = getKeyDescriptor().createTargetDomainResult( fetchablePath, sqlAstCreationState.getFromClauseAccess().getTableGroup( fetchParent.getNavigablePath() ), + fetchParent, creationState ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java index ef7eca814d..c12abbadc5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleForeignKeyDescriptor.java @@ -157,44 +157,43 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa public DomainResult createKeyDomainResult( NavigablePath navigablePath, TableGroup tableGroup, + FetchParent fetchParent, DomainResultCreationState creationState) { return createDomainResult( navigablePath, tableGroup, keySide.getModelPart(), + fetchParent, creationState ); } @Override - public DomainResult createTargetDomainResult(NavigablePath navigablePath, TableGroup tableGroup, DomainResultCreationState creationState) { + public DomainResult createTargetDomainResult( + NavigablePath navigablePath, + TableGroup tableGroup, + FetchParent fetchParent, + DomainResultCreationState creationState) { return createDomainResult( navigablePath, tableGroup, targetSide.getModelPart(), + fetchParent, creationState ); } - @Override - public DomainResult createCollectionFetchDomainResult( - NavigablePath collectionPath, - TableGroup tableGroup, - DomainResultCreationState creationState) { - return createDomainResult( collectionPath, tableGroup, targetSide.getModelPart(), creationState ); - } - @Override public DomainResult createDomainResult( NavigablePath navigablePath, TableGroup tableGroup, Nature side, - DomainResultCreationState creationState) { + FetchParent fetchParent, DomainResultCreationState creationState) { if ( side == Nature.KEY ) { - return createDomainResult( navigablePath, tableGroup, keySide.getModelPart(), creationState ); + return createDomainResult( navigablePath, tableGroup, keySide.getModelPart(), fetchParent, creationState ); } else { - return createDomainResult( navigablePath, tableGroup, targetSide.getModelPart(), creationState ); + return createDomainResult( navigablePath, tableGroup, targetSide.getModelPart(), fetchParent, creationState ); } } @@ -204,7 +203,7 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) { - return createDomainResult( navigablePath, tableGroup, keySide.getModelPart(), creationState ); + return createDomainResult( navigablePath, tableGroup, keySide.getModelPart(), null, creationState ); } @Override @@ -228,6 +227,7 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa NavigablePath navigablePath, TableGroup tableGroup, SelectableMapping selectableMapping, + FetchParent fetchParent, DomainResultCreationState creationState) { final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver(); @@ -274,6 +274,7 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa ) ), selectableMapping.getJdbcMapping().getJavaTypeDescriptor(), + fetchParent, sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index c210a6696d..b9ebfb0359 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -803,6 +803,7 @@ public class ToOneAttributeMapping fetchablePath, parentTableGroup, sideNature, + fetchParent, creationState ); } @@ -966,6 +967,7 @@ public class ToOneAttributeMapping creationState.getSqlAstCreationState() .getFromClauseAccess() .findTableGroup( realFetchParent.getNavigablePath() ), + fetchParent, creationState ); } @@ -1023,6 +1025,7 @@ public class ToOneAttributeMapping fetchablePath, tableGroup, sideNature, + fetchParent, creationState ), isSelectByUniqueKey( sideNature ) @@ -1069,6 +1072,7 @@ public class ToOneAttributeMapping keyResult = foreignKeyDescriptor.createKeyDomainResult( fetchablePath, parentTableGroup, + fetchParent, creationState ); } @@ -1076,6 +1080,7 @@ public class ToOneAttributeMapping keyResult = foreignKeyDescriptor.createTargetDomainResult( fetchablePath, parentTableGroup, + fetchParent, creationState ); } @@ -1134,6 +1139,7 @@ public class ToOneAttributeMapping fetchablePath, parentTableGroup, side, + fetchParent, creationState ); final boolean selectByUniqueKey = isSelectByUniqueKey( side ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/DomainResultCreationStateImpl.java b/hibernate-core/src/main/java/org/hibernate/query/results/DomainResultCreationStateImpl.java index b0cb65f458..c3f4035d12 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/DomainResultCreationStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/DomainResultCreationStateImpl.java @@ -293,7 +293,7 @@ public class DomainResultCreationStateImpl public SqlSelection resolveSqlSelection( Expression expression, JavaType javaType, - TypeConfiguration typeConfiguration) { + FetchParent fetchParent, TypeConfiguration typeConfiguration) { if ( expression == null ) { throw new IllegalArgumentException( "Expression cannot be null" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java index b4f041e22e..6c3b35b911 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEmbeddableValuedModelPart.java @@ -92,6 +92,7 @@ public class CompleteFetchBuilderEmbeddableValuedModelPart } ), modelPart.getJavaType(), + null, creationStateImpl.getSessionFactory().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java index a608c45eca..32dcc46d21 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteFetchBuilderEntityValuedModelPart.java @@ -96,6 +96,7 @@ public class CompleteFetchBuilderEntityValuedModelPart } ), modelPart.getJavaType(), + null, creationStateImpl.getSessionFactory().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java index 2c5f47781a..f5dd8a1ef8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicModelPart.java @@ -87,6 +87,7 @@ public class CompleteResultBuilderBasicModelPart } ), modelPart.getJavaType(), + null, creationStateImpl.getSessionFactory().getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java index 4ceeed4891..1e6dfbb9f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedConverted.java @@ -132,6 +132,7 @@ public class CompleteResultBuilderBasicValuedConverted implements CompleteR } ), valueConverter.getDomainJavaType(), + null, sessionFactory.getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java index 0ad4a41af4..3dc5a58363 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderBasicValuedStandard.java @@ -138,6 +138,7 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB } ), explicitJavaType, + null, sessionFactory.getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java index 41e3ce7778..31a2e732f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/complete/CompleteResultBuilderCollectionStandard.java @@ -168,6 +168,7 @@ public class CompleteResultBuilderCollectionStandard implements CompleteResultBu } ), selectableMapping.getJdbcMapping().getMappedJavaType(), + null, creationStateImpl.getSessionFactory().getTypeConfiguration() ); }; diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java index 0c12d0946d..23820c60b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderLegacy.java @@ -247,6 +247,7 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue } ), jdbcMapping.getMappedJavaType(), + null, domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java index 727ccb9496..5c78902e19 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicFetchBuilderStandard.java @@ -97,6 +97,7 @@ public class DynamicFetchBuilderStandard } ), selectableMapping.getJdbcMapping().getMappedJavaType(), + null, domainResultCreationState.getSqlAstCreationState() .getCreationContext() .getSessionFactory() diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java index 50cdfcb79e..3c40c899df 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderAttribute.java @@ -89,6 +89,7 @@ public class DynamicResultBuilderAttribute implements DynamicResultBuilder, Nati } ), attributeMapping.getJavaType(), + null, domainResultCreationState.getSqlAstCreationState() .getCreationContext() .getSessionFactory() diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicConverted.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicConverted.java index aaa27eb8f8..caec50aad8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicConverted.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicConverted.java @@ -127,6 +127,7 @@ public class DynamicResultBuilderBasicConverted implements DynamicResultBui } ), basicValueConverter.getDomainJavaType(), + null, typeConfiguration ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicStandard.java index 0c98a5e79f..1284a47601 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderBasicStandard.java @@ -164,6 +164,7 @@ public class DynamicResultBuilderBasicStandard implements DynamicResultBuilderBa final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( expression, javaType, + null, sessionFactory.getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java index 68c1fe311e..63e498c95f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/dynamic/DynamicResultBuilderEntityStandard.java @@ -290,6 +290,7 @@ public class DynamicResultBuilderEntityStandard } ), jdbcMapping.getMappedJavaType(), + null, domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java index 3d9ac52657..c69431726f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderBasic.java @@ -86,6 +86,7 @@ public class ImplicitFetchBuilderBasic implements ImplicitFetchBuilder, BasicVal final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection( expression, fetchable.getJavaType(), + parent, domainResultCreationState.getSqlAstCreationState() .getCreationContext() .getSessionFactory() diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java index c8084e6396..ec1a8a8057 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java @@ -106,6 +106,7 @@ public class SelfRenderingFunctionSqlAstExpression .resolveSqlSelection( this, type.getExpressibleJavaType(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ) .getValuesArrayPosition(), @@ -183,6 +184,7 @@ public class SelfRenderingFunctionSqlAstExpression sqlExpressionResolver.resolveSqlSelection( this, type.getExpressibleJavaType(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 90f3074742..ecf91df482 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -492,6 +492,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base this.deduplicateSelectionItems = deduplicateSelectionItems; if ( statement instanceof SqmSelectStatement ) { + final SqmQueryPart queryPart = ( (SqmSelectStatement) statement ).getQueryPart(); // NOTE: note the difference here between `JpaSelection#getSelectionItems` // and `SqmSelectClause#getSelections`. // @@ -502,13 +503,21 @@ public abstract class BaseSqmToSqlAstConverter extends Base // - `#getSelections` returns top-level selections. These are ultimately the // domain-results of the query this.domainResults = new ArrayList<>( - ( (SqmSelectStatement) statement ).getQueryPart() - .getFirstQuerySpec() + queryPart.getFirstQuerySpec() .getSelectClause() .getSelections() .size() ); + // We can't deduplicate select items with query groups, + // otherwise a query might fail with inconsistent select items + // + // select e1.id, e1.id from Entity1 e1 + // union all + // select e2.id, e2.parentId from Entity2 e2 + if ( queryPart instanceof SqmQueryGroup ) { + this.deduplicateSelectionItems = false; + } final AppliedGraph appliedGraph = queryOptions.getAppliedGraph(); if ( appliedGraph != null && appliedGraph.getSemantic() != null && appliedGraph.getGraph() != null ) { this.entityGraphTraversalState = new StandardEntityGraphTraversalStateImpl( @@ -6914,8 +6923,9 @@ public abstract class BaseSqmToSqlAstConverter extends Base public SqlSelection resolveSqlSelection( Expression expression, JavaType javaType, + FetchParent fetchParent, TypeConfiguration typeConfiguration) { - return delegate.resolveSqlSelection( expression, javaType, typeConfiguration ); + return delegate.resolveSqlSelection( expression, javaType, fetchParent, typeConfiguration ); } public void setSqmAliasedNodeCollector(SqmAliasedNodeCollector sqmAliasedNodeCollector) { @@ -6967,8 +6977,9 @@ public abstract class BaseSqmToSqlAstConverter extends Base public SqlSelection resolveSqlSelection( Expression expression, JavaType javaType, + FetchParent fetchParent, TypeConfiguration typeConfiguration) { - SqlSelection selection = delegate.resolveSqlSelection( expression, javaType, typeConfiguration ); + SqlSelection selection = delegate.resolveSqlSelection( expression, javaType, fetchParent, typeConfiguration ); List sqlSelectionList = sqlSelectionsForSqmSelection[index]; if ( sqlSelectionList == null ) { sqlSelectionsForSqmSelection[index] = sqlSelectionList = new ArrayList<>(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java index c0c6edc7e2..88b257712c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EntityValuedPathInterpretation.java @@ -262,6 +262,7 @@ public class EntityValuedPathInterpretation extends AbstractSqmPathInterpreta creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( sqlExpression, getExpressionType().getJavaType(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java index 6e958b998f..5c80e0da90 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java @@ -22,6 +22,7 @@ import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.SqlSelectionExpression; +import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.spi.TypeConfiguration; @@ -139,7 +140,7 @@ public class SqlAstProcessingStateImpl public SqlSelection resolveSqlSelection( Expression expression, JavaType javaType, - TypeConfiguration typeConfiguration) { + FetchParent fetchParent, TypeConfiguration typeConfiguration) { throw new ConversionException( "Unexpected call to resolve SqlSelection outside of QuerySpec processing" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java index 9d08701a17..18c8a99c62 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java @@ -21,6 +21,7 @@ import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.select.QueryPart; import org.hibernate.sql.ast.tree.select.QuerySpec; import org.hibernate.sql.ast.tree.select.SelectClause; +import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.spi.TypeConfiguration; @@ -65,6 +66,7 @@ public class SqlAstQueryPartProcessingStateImpl // SqlExpressionResolver private Map sqlSelectionMap; + private Map> fetchParentSqlSelectionMap; @Override protected Map sqlSelectionMap() { @@ -75,6 +77,7 @@ public class SqlAstQueryPartProcessingStateImpl public SqlSelection resolveSqlSelection( Expression expression, JavaType javaType, + FetchParent fetchParent, TypeConfiguration typeConfiguration) { final SqlSelection existing; if ( sqlSelectionMap == null ) { @@ -88,6 +91,31 @@ public class SqlAstQueryPartProcessingStateImpl if ( existing != null && deduplicateSelectionItems ) { return existing; } + final Map fetchParentSelections; + if ( !deduplicateSelectionItems && fetchParent != null ) { + // De-duplicate selection items within the root of a fetch parent + final FetchParent root = fetchParent.getRoot(); + if ( fetchParentSqlSelectionMap == null ) { + fetchParentSqlSelectionMap = new HashMap<>(); + fetchParentSqlSelectionMap.put( root, fetchParentSelections = new HashMap<>() ); + } + else { + final Map map = fetchParentSqlSelectionMap.get( root ); + if ( map == null ) { + fetchParentSqlSelectionMap.put( root, fetchParentSelections = new HashMap<>() ); + } + else { + fetchParentSelections = map; + } + } + final SqlSelection sqlSelection = fetchParentSelections.get( expression ); + if ( sqlSelection != null ) { + return sqlSelection; + } + } + else { + fetchParentSelections = null; + } final SelectClause selectClause = ( (QuerySpec) queryPart ).getSelectClause(); final int valuesArrayPosition = selectClause.getSqlSelections().size(); @@ -98,9 +126,13 @@ public class SqlAstQueryPartProcessingStateImpl typeConfiguration ); + selectClause.addSqlSelection( sqlSelection ); + sqlSelectionMap.put( expression, sqlSelection ); - selectClause.addSqlSelection( sqlSelection ); + if ( fetchParentSelections != null ) { + fetchParentSelections.put( expression, sqlSelection ); + } return sqlSelection; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java index e299c54a63..19fdac66cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java @@ -120,6 +120,7 @@ public class SqmParameterInterpretation implements Expression, DomainResultProdu final SqlSelection sqlSelection = creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( resolvedExpression, sqmExpressible.getExpressibleJavaType(), + null, sessionFactory.getTypeConfiguration() ); @@ -164,6 +165,7 @@ public class SqmParameterInterpretation implements Expression, DomainResultProdu return creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( resolvedExpression, sqmExpressible.getExpressibleJavaType(), + null, sessionFactory.getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/Conversion.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/Conversion.java index 5da35acb66..420c522f89 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/Conversion.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/Conversion.java @@ -63,6 +63,7 @@ public class Conversion creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, type.getJdbcMapping().getJavaTypeDescriptor(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ).getValuesArrayPosition(), resultVariable, @@ -78,6 +79,7 @@ public class Conversion sqlExpressionResolver.resolveSqlSelection( this, type.getJdbcMapping().getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java index 1b6029c194..b977457f10 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlExpressionResolver.java @@ -12,6 +12,7 @@ import java.util.function.Function; import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.from.TableReference; +import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.spi.TypeConfiguration; @@ -77,5 +78,5 @@ public interface SqlExpressionResolver { SqlSelection resolveSqlSelection( Expression expression, JavaType javaType, - TypeConfiguration typeConfiguration); + FetchParent fetchParent, TypeConfiguration typeConfiguration); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Any.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Any.java index 2f9c3b87e3..3155900b7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Any.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Any.java @@ -53,6 +53,7 @@ public class Any implements Expression, DomainResultProducer { creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, javaType, + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ).getValuesArrayPosition(), resultVariable, @@ -68,6 +69,7 @@ public class Any implements Expression, DomainResultProducer { sqlExpressionResolver.resolveSqlSelection( this, type.getJdbcMappings().get( 0 ).getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java index 3c002d8e4f..214f435577 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java @@ -70,6 +70,7 @@ public class BinaryArithmeticExpression implements Expression, DomainResultProdu return creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, resultType.getJdbcMapping().getJavaTypeDescriptor(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java index b38a4973d6..01be0e501a 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java @@ -68,6 +68,7 @@ public class CaseSearchedExpression implements Expression, DomainResultProducer .resolveSqlSelection( this, type.getExpressibleJavaType(), + null, creationState.getSqlAstCreationState() .getCreationContext() .getSessionFactory() @@ -89,6 +90,7 @@ public class CaseSearchedExpression implements Expression, DomainResultProducer sqlExpressionResolver.resolveSqlSelection( this, type.getExpressibleJavaType(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java index 535d1efe64..21956393d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java @@ -66,6 +66,7 @@ public class CaseSimpleExpression implements Expression, DomainResultProducer { creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, javaType, + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ).getValuesArrayPosition(), resultVariable, @@ -81,6 +82,7 @@ public class CaseSimpleExpression implements Expression, DomainResultProducer { sqlExpressionResolver.resolveSqlSelection( this, type.getJdbcMappings().get( 0 ).getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ConvertedQueryLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ConvertedQueryLiteral.java index 51b65d59c9..58973f9534 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ConvertedQueryLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ConvertedQueryLiteral.java @@ -76,6 +76,7 @@ public class ConvertedQueryLiteral implements Literal, DomainResultProducer expressionResolver.resolveSqlSelection( this, relationalMapping.getExpressibleJavaType(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Duration.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Duration.java index d5c86ddef4..660e0c5523 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Duration.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Duration.java @@ -61,6 +61,7 @@ public class Duration implements Expression, DomainResultProducer { creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, type.getJdbcMapping().getJavaTypeDescriptor(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ).getValuesArrayPosition(), resultVariable, @@ -76,6 +77,7 @@ public class Duration implements Expression, DomainResultProducer { sqlExpressionResolver.resolveSqlSelection( this, type.getJdbcMapping().getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java index e1794a24a1..f2ae32afbe 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java @@ -113,6 +113,7 @@ public class EntityTypeLiteral implements Expression, MappingModelExpressible, D .resolveSqlSelection( this, discriminatorType.getExpressibleJavaType(), + null, creationState.getSqlAstCreationState().getCreationContext() .getMappingMetamodel().getTypeConfiguration() ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Every.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Every.java index 28b9a15176..464a650bcb 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Every.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Every.java @@ -53,6 +53,7 @@ public class Every implements Expression, DomainResultProducer { creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, javaType, + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ).getValuesArrayPosition(), resultVariable, @@ -68,6 +69,7 @@ public class Every implements Expression, DomainResultProducer { sqlExpressionResolver.resolveSqlSelection( this, type.getJdbcMappings().get( 0 ).getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/JdbcLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/JdbcLiteral.java index 6cf1916fa6..b041ee6b4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/JdbcLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/JdbcLiteral.java @@ -140,6 +140,7 @@ public class JdbcLiteral implements Literal, MappingModelExpressible, Doma final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( this, jdbcMapping.getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); @@ -155,6 +156,7 @@ public class JdbcLiteral implements Literal, MappingModelExpressible, Doma sqlExpressionResolver.resolveSqlSelection( this, jdbcMapping.getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Over.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Over.java index 67040de44c..7546fcf439 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Over.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Over.java @@ -137,6 +137,7 @@ public class Over implements Expression, DomainResultProducer { return creationState.getSqlExpressionResolver().resolveSqlSelection( this, expression.getExpressionType().getJdbcMappings().get( 0 ).getMappedJavaType(), + null, creationState.getCreationContext().getSessionFactory().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java index 27c7124eaa..d8712a34fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java @@ -105,6 +105,7 @@ public class QueryLiteral implements Literal, DomainResultProducer { final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( this, type.getMappedType().getMappedJavaType(), + null, creationState.getSqlAstCreationState() .getCreationContext() .getSessionFactory() @@ -147,6 +148,7 @@ public class QueryLiteral implements Literal, DomainResultProducer { creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, type.getJdbcMapping().getJavaTypeDescriptor(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java index d98bfed001..d009df311f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java @@ -72,6 +72,7 @@ public class SqlTuple implements Expression, SqlTupleContainer, DomainResultProd valuesArrayPositions[i] = creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( expressions.get( i ), javaType, + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ).getValuesArrayPosition(); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java index 50bf81f310..4f1568de68 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java @@ -60,6 +60,7 @@ public class UnaryOperation implements Expression, DomainResultProducer { final SqlSelection sqlSelection = creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, type.getJdbcMapping().getJavaTypeDescriptor(), + null, creationState.getSqlAstCreationState().getCreationContext().getMappingMetamodel().getTypeConfiguration() ); @@ -79,6 +80,7 @@ public class UnaryOperation implements Expression, DomainResultProducer { sqlExpressionResolver.resolveSqlSelection( this, type.getJdbcMapping().getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/predicate/Predicate.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/predicate/Predicate.java index 1030a661dc..bd5b1ccb14 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/predicate/Predicate.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/predicate/Predicate.java @@ -40,6 +40,7 @@ public interface Predicate extends Expression, DomainResultProducer { final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( this, javaType, + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); @@ -55,6 +56,7 @@ public interface Predicate extends Expression, DomainResultProducer { sqlExpressionResolver.resolveSqlSelection( this, getExpressionType().getJdbcMappings().get( 0 ).getJavaTypeDescriptor(), + null, sqlAstCreationState.getCreationContext().getMappingMetamodel().getTypeConfiguration() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java index 849e06e789..bbd14605d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/QuerySpec.java @@ -13,7 +13,6 @@ import java.util.function.Function; import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.query.sqm.sql.internal.DomainResultProducer; -import org.hibernate.query.sqm.tree.expression.SqmAliasedNodeRef; import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.spi.SqlAstTreeHelper; import org.hibernate.sql.ast.spi.SqlExpressionResolver; @@ -154,6 +153,7 @@ public class QuerySpec extends QueryPart implements SqlAstNode, PredicateContain creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( this, jdbcMapping.getJavaTypeDescriptor(), + null, typeConfiguration ); } @@ -175,6 +175,7 @@ public class QuerySpec extends QueryPart implements SqlAstNode, PredicateContain final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection( this, descriptor, + null, typeConfiguration ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchParent.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchParent.java index 4062c8222a..165291fd0d 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchParent.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchParent.java @@ -88,6 +88,13 @@ public interface FetchParent extends DomainResultGraphNode { Fetch findFetch(Fetchable fetchable); + default FetchParent getRoot() { + if ( this instanceof Fetch ) { + return ( (Fetch) this ).getFetchParent().getRoot(); + } + return this; + } + default Fetch generateFetchableFetch( Fetchable fetchable, NavigablePath fetchablePath, diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/CollectionDomainResult.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/CollectionDomainResult.java index 0082d3d523..eb375e05e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/CollectionDomainResult.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/CollectionDomainResult.java @@ -56,6 +56,7 @@ public class CollectionDomainResult implements DomainResult, CollectionResultGra fkResult = loadingAttribute.getKeyDescriptor().createKeyDomainResult( loadingPath, tableGroup, + this, creationState ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EagerCollectionFetch.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EagerCollectionFetch.java index f90a1a85dc..8ce8aa9d7f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EagerCollectionFetch.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/EagerCollectionFetch.java @@ -90,8 +90,18 @@ public class EagerCollectionFetch extends CollectionFetch implements FetchParent final ForeignKeyDescriptor keyDescriptor = fetchedAttribute.getKeyDescriptor(); // The collection key must be fetched from the side of the declaring type of the attribute // So that this is guaranteed to be not-null - collectionKeyResult = keyDescriptor.createTargetDomainResult( fetchedPath, parentTableGroup, creationState ); - collectionValueKeyResult = keyDescriptor.createKeyDomainResult( fetchedPath, collectionTableGroup, creationState ); + collectionKeyResult = keyDescriptor.createTargetDomainResult( + fetchedPath, + parentTableGroup, + fetchParent, + creationState + ); + collectionValueKeyResult = keyDescriptor.createKeyDomainResult( + fetchedPath, + collectionTableGroup, + fetchParent, + creationState + ); fetches = creationState.visitFetches( this ); if ( fetchedAttribute.getIndexDescriptor() != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java index 13fbec6358..a94b782b8b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableForeignKeyResultImpl.java @@ -18,6 +18,7 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultAssembler; 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.FetchParentAccess; import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.embeddable.EmbeddableInitializer; @@ -31,17 +32,25 @@ public class EmbeddableForeignKeyResultImpl implements EmbeddableResultGraphNode, DomainResult { private final String resultVariable; + private final FetchParent fetchParent; public EmbeddableForeignKeyResultImpl( NavigablePath navigablePath, EmbeddableValuedModelPart embeddableValuedModelPart, String resultVariable, + FetchParent fetchParent, DomainResultCreationState creationState) { super( embeddableValuedModelPart.getEmbeddableTypeDescriptor(), navigablePath ); this.resultVariable = resultVariable; + this.fetchParent = fetchParent; this.fetches = creationState.visitFetches( this ); } + @Override + public FetchParent getRoot() { + return fetchParent.getRoot(); + } + @Override public boolean containsAnyNonScalarResults() { return true; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityResultGraphNode.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityResultGraphNode.java index ab082ae006..5679d40364 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityResultGraphNode.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityResultGraphNode.java @@ -114,6 +114,7 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent .createKeyDomainResult( navigablePath.getParent(), entityTableGroup, + this, creationState ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedResultImpl.java index 44ad410c41..533f188be9 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedResultImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedResultImpl.java @@ -40,6 +40,7 @@ public class EntityDelayedResultImpl implements DomainResult { this.identifierResult = entityValuedModelPart.getForeignKeyDescriptor().createKeyDomainResult( navigablePath.append( EntityIdentifierMapping.ROLE_LOCAL_NAME ), rootTableGroup, + null, creationState ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/NotFoundSnapshotResult.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/NotFoundSnapshotResult.java index 8acb238868..970792ae4d 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/NotFoundSnapshotResult.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/NotFoundSnapshotResult.java @@ -44,8 +44,13 @@ public class NotFoundSnapshotResult implements DomainResult { // however, that would mean a 1-1 with a join-table which // is pretty odd mapping final ForeignKeyDescriptor fkDescriptor = toOneMapping.getForeignKeyDescriptor(); - this.keyResult = fkDescriptor.createKeyDomainResult( navigablePath, keyTableGroup, creationState ); - this.targetResult = fkDescriptor.createTargetDomainResult( navigablePath, targetTableGroup, creationState ); + this.keyResult = fkDescriptor.createKeyDomainResult( navigablePath, keyTableGroup, null, creationState ); + this.targetResult = fkDescriptor.createTargetDomainResult( + navigablePath, + targetTableGroup, + null, + creationState + ); } @Override