diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/AbstractFetchParent.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/AbstractFetchParent.java index ac3037b65f..2540649b05 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/AbstractFetchParent.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/AbstractFetchParent.java @@ -15,15 +15,13 @@ import org.hibernate.type.descriptor.java.JavaType; * @author Steve Ebersole */ public abstract class AbstractFetchParent implements FetchParent { - private final FetchableContainer fetchContainer; private final NavigablePath navigablePath; private ImmutableFetchList fetches = ImmutableFetchList.EMPTY; private boolean hasJoinFetches; private boolean containsCollectionFetches; - public AbstractFetchParent(FetchableContainer fetchContainer, NavigablePath navigablePath) { - this.fetchContainer = fetchContainer; + public AbstractFetchParent(NavigablePath navigablePath) { this.navigablePath = navigablePath; } @@ -38,9 +36,7 @@ public abstract class AbstractFetchParent implements FetchParent { this.containsCollectionFetches = newFetches.containsCollectionFetches(); } - public FetchableContainer getFetchContainer() { - return fetchContainer; - } + public abstract FetchableContainer getFetchContainer(); @Override public NavigablePath getNavigablePath() { @@ -49,12 +45,12 @@ public abstract class AbstractFetchParent implements FetchParent { @Override public JavaType getResultJavaType() { - return fetchContainer.getJavaType(); + return getFetchContainer().getJavaType(); } @Override public FetchableContainer getReferencedMappingContainer() { - return fetchContainer; + return getFetchContainer(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableFetchImpl.java index 7221580dc5..c1cf091881 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableFetchImpl.java @@ -46,6 +46,7 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements private final TableGroup tableGroup; private final boolean hasTableGroup; private final SqlSelection aggregateSelection; + private final EmbeddableMappingType fetchContainer; public AggregateEmbeddableFetchImpl( NavigablePath navigablePath, @@ -54,7 +55,8 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements FetchTiming fetchTiming, boolean hasTableGroup, DomainResultCreationState creationState) { - super( embeddedPartDescriptor.getEmbeddableTypeDescriptor(), navigablePath ); + super( navigablePath ); + this.fetchContainer = embeddedPartDescriptor.getEmbeddableTypeDescriptor(); this.fetchParent = fetchParent; this.fetchTiming = fetchTiming; @@ -84,7 +86,7 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver(); final TableReference tableReference = tableGroup.getPrimaryTableReference(); - final SelectableMapping selectableMapping = embeddedPartDescriptor.getEmbeddableTypeDescriptor().getAggregateMapping(); + final SelectableMapping selectableMapping = fetchContainer.getAggregateMapping(); final Expression expression = sqlExpressionResolver.resolveSqlExpression( tableReference, selectableMapping ); final TypeConfiguration typeConfiguration = sqlAstCreationState.getCreationContext() .getSessionFactory() @@ -115,7 +117,7 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements @Override public EmbeddableMappingType getFetchContainer() { - return (EmbeddableMappingType) super.getFetchContainer(); + return fetchContainer; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableResultImpl.java index 8c2bc7754b..63072c0aaf 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableResultImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/AggregateEmbeddableResultImpl.java @@ -48,13 +48,15 @@ public class AggregateEmbeddableResultImpl extends AbstractFetchParent implem private final boolean containsAnyNonScalars; private final NavigablePath initializerNavigablePath; private final SqlSelection aggregateSelection; + private final EmbeddableMappingType fetchContainer; public AggregateEmbeddableResultImpl( NavigablePath navigablePath, EmbeddableValuedModelPart embeddedPartDescriptor, String resultVariable, DomainResultCreationState creationState) { - super( embeddedPartDescriptor.getEmbeddableTypeDescriptor(), navigablePath ); + super( navigablePath ); + this.fetchContainer = embeddedPartDescriptor.getEmbeddableTypeDescriptor(); this.resultVariable = resultVariable; /* An `{embeddable_result}` sub-path is created for the corresponding initializer to differentiate it from a fetch-initializer if this embedded is also fetched. @@ -127,7 +129,7 @@ public class AggregateEmbeddableResultImpl extends AbstractFetchParent implem @Override public EmbeddableMappingType getFetchContainer() { - return (EmbeddableMappingType) super.getFetchContainer(); + return this.fetchContainer; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java index 78c48210a3..39e476fd89 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableExpressionResultImpl.java @@ -36,6 +36,7 @@ import org.hibernate.type.spi.TypeConfiguration; public class EmbeddableExpressionResultImpl extends AbstractFetchParent implements EmbeddableResultGraphNode, DomainResult, EmbeddableResult { private final String resultVariable; private final boolean containsAnyNonScalars; + private final EmbeddableMappingType fetchContainer; public EmbeddableExpressionResultImpl( NavigablePath navigablePath, @@ -43,7 +44,8 @@ public class EmbeddableExpressionResultImpl extends AbstractFetchParent imple SqlTuple sqlExpression, String resultVariable, DomainResultCreationState creationState) { - super( modelPart.getEmbeddableTypeDescriptor(), navigablePath ); + super( navigablePath ); + this.fetchContainer = modelPart.getEmbeddableTypeDescriptor(); this.resultVariable = resultVariable; final ImmutableFetchList.Builder fetches = new ImmutableFetchList.Builder( modelPart ); @@ -100,7 +102,7 @@ public class EmbeddableExpressionResultImpl extends AbstractFetchParent imple @Override public EmbeddableMappingType getFetchContainer() { - return (EmbeddableMappingType) super.getFetchContainer(); + return this.fetchContainer; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableFetchImpl.java index 9bfebeea71..fe8ccc7d40 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableFetchImpl.java @@ -38,6 +38,7 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab private final FetchTiming fetchTiming; private final TableGroup tableGroup; private final boolean hasTableGroup; + private final EmbeddableMappingType fetchContainer; public EmbeddableFetchImpl( NavigablePath navigablePath, @@ -46,7 +47,8 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab FetchTiming fetchTiming, boolean hasTableGroup, DomainResultCreationState creationState) { - super( embeddedPartDescriptor.getEmbeddableTypeDescriptor(), navigablePath ); + super( navigablePath ); + this.fetchContainer = embeddedPartDescriptor.getEmbeddableTypeDescriptor(); this.fetchParent = fetchParent; this.fetchTiming = fetchTiming; @@ -80,7 +82,8 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab * For Hibernate Reactive */ protected EmbeddableFetchImpl(EmbeddableFetchImpl original) { - super( original.getFetchContainer(), original.getNavigablePath() ); + super( original.getNavigablePath() ); + this.fetchContainer = original.getFetchContainer(); fetchParent = original.fetchParent; fetchTiming = original.fetchTiming; tableGroup = original.tableGroup; @@ -104,7 +107,7 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab @Override public EmbeddableMappingType getFetchContainer() { - return (EmbeddableMappingType) super.getFetchContainer(); + return this.fetchContainer; } @Override 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 8824861aff..61daf7aab9 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 @@ -34,6 +34,7 @@ public class EmbeddableForeignKeyResultImpl private final String resultVariable; private final FetchParent fetchParent; + private final EmbeddableMappingType fetchContainer; public EmbeddableForeignKeyResultImpl( NavigablePath navigablePath, @@ -41,7 +42,8 @@ public class EmbeddableForeignKeyResultImpl String resultVariable, FetchParent fetchParent, DomainResultCreationState creationState) { - super( embeddableValuedModelPart.getEmbeddableTypeDescriptor(), navigablePath ); + super( navigablePath ); + this.fetchContainer = embeddableValuedModelPart.getEmbeddableTypeDescriptor(); this.resultVariable = resultVariable; this.fetchParent = fetchParent; resetFetches( creationState.visitFetches( this ) ); @@ -117,7 +119,7 @@ public class EmbeddableForeignKeyResultImpl @Override public EmbeddableMappingType getFetchContainer() { - return (EmbeddableMappingType) super.getFetchContainer(); + return fetchContainer; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java index b444c21dac..3c60703425 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java @@ -33,13 +33,15 @@ public class EmbeddableResultImpl extends AbstractFetchParent implements Embe private final String resultVariable; private final boolean containsAnyNonScalars; private final NavigablePath initializerNavigablePath; + private final EmbeddableMappingType fetchContainer; public EmbeddableResultImpl( NavigablePath navigablePath, EmbeddableValuedModelPart modelPart, String resultVariable, DomainResultCreationState creationState) { - super( modelPart.getEmbeddableTypeDescriptor(), navigablePath ); + super( navigablePath ); + this.fetchContainer = modelPart.getEmbeddableTypeDescriptor(); this.resultVariable = resultVariable; /* An `{embeddable_result}` sub-path is created for the corresponding initializer to differentiate it from a fetch-initializer if this embedded is also fetched. @@ -98,7 +100,7 @@ public class EmbeddableResultImpl extends AbstractFetchParent implements Embe @Override public EmbeddableMappingType getFetchContainer() { - return (EmbeddableMappingType) super.getFetchContainer(); + return this.fetchContainer; } @Override 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 6f6e79b03b..42aba468c3 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 @@ -17,6 +17,7 @@ import org.hibernate.sql.results.graph.DomainResult; 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.FetchableContainer; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.type.descriptor.java.JavaType; @@ -29,9 +30,11 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent private Fetch identifierFetch; private BasicFetch discriminatorFetch; private DomainResult rowIdResult; + private final EntityValuedModelPart fetchContainer; public AbstractEntityResultGraphNode(EntityValuedModelPart referencedModelPart, NavigablePath navigablePath) { - super( referencedModelPart, navigablePath ); + super( navigablePath ); + this.fetchContainer = referencedModelPart; } @Override @@ -72,7 +75,12 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent @Override public EntityValuedModelPart getEntityValuedModelPart() { - return (EntityValuedModelPart) getFetchContainer(); + return this.fetchContainer; + } + + @Override + public FetchableContainer getFetchContainer() { + return this.fetchContainer; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractNonLazyEntityFetch.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractNonLazyEntityFetch.java index 3f40708279..4545f5359b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractNonLazyEntityFetch.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractNonLazyEntityFetch.java @@ -13,6 +13,7 @@ import org.hibernate.sql.results.graph.AssemblerCreationState; import org.hibernate.sql.results.graph.DomainResultAssembler; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.FetchParentAccess; +import org.hibernate.sql.results.graph.FetchableContainer; import org.hibernate.sql.results.graph.entity.internal.EntityAssembler; /** @@ -22,18 +23,25 @@ import org.hibernate.sql.results.graph.entity.internal.EntityAssembler; */ public abstract class AbstractNonLazyEntityFetch extends AbstractFetchParent implements EntityFetch { private final FetchParent fetchParent; + private final EntityValuedFetchable fetchContainer; public AbstractNonLazyEntityFetch( FetchParent fetchParent, EntityValuedFetchable fetchedPart, NavigablePath navigablePath) { - super( fetchedPart, navigablePath ); + super( navigablePath ); + this.fetchContainer = fetchedPart; this.fetchParent = fetchParent; } @Override public EntityValuedFetchable getEntityValuedModelPart() { - return (EntityValuedFetchable) getFetchContainer(); + return fetchContainer; + } + + @Override + public FetchableContainer getFetchContainer() { + return fetchContainer; } @Override