diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java index 480aed4224..2faa26c4f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java @@ -756,7 +756,7 @@ public class LoaderSelectBuilder { } } else if ( loadQueryInfluencers.getEnabledCascadingFetchProfile() != null ) { - final CascadeStyle cascadeStyle = ( (AttributeMapping) fetchable ).getAttributeMetadataAccess() + final CascadeStyle cascadeStyle = fetchable.asAttributeMapping().getAttributeMetadataAccess() .resolveAttributeMetadata( fetchable.findContainingEntityMapping() ) .getCascadeStyle(); final CascadingAction cascadingAction = loadQueryInfluencers.getEnabledCascadingFetchProfile() diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java index 7fb12d8605..0d76bf27a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMapping.java @@ -86,4 +86,10 @@ public interface AttributeMapping //noinspection unchecked,rawtypes return ( (JavaType) getJavaType() ).getComparator().compare( value1, value2 ); } + + @Override //Overrides multiple interfaces! + default AttributeMapping asAttributeMapping() { + return this; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java index 1ebfb346e1..850e3c7c4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java @@ -97,6 +97,10 @@ public interface ModelPart extends MappingModelExpressible { return 0; } + default AttributeMapping asAttributeMapping() { + return null; + } + @FunctionalInterface interface JdbcValueConsumer { void consume(Object value, SelectableMapping jdbcValueMapping); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index ef0e5dafe3..3d5825047e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -1859,14 +1859,17 @@ public abstract class AbstractEntityPersister if ( fetchParent instanceof EmbeddableResultGraphNode ) { return true; } - else if ( fetchable instanceof AttributeMapping ) { - final int propertyNumber = ( (AttributeMapping) fetchable ).getStateArrayPosition(); + else { + final AttributeMapping attributeMapping = fetchable.asAttributeMapping(); + if ( attributeMapping != null ) { + final int propertyNumber = attributeMapping.getStateArrayPosition(); // final int tableNumber = getSubclassPropertyTableNumber( propertyNumber ); // return !isSubclassTableSequentialSelect( tableNumber ) && propertySelectable[propertyNumber]; - return propertySelectable[propertyNumber]; - } - else { - return true; + return propertySelectable[propertyNumber]; + } + else { + return true; + } } } @@ -4187,7 +4190,7 @@ public abstract class AbstractEntityPersister } else { for ( int i = 0; i < staticFetchableList.size(); i++ ) { - final AttributeMapping attribute = (AttributeMapping) staticFetchableList.get( i ); + final AttributeMapping attribute = staticFetchableList.get( i ).asAttributeMapping(); final Object value = values[i]; if ( value != UNFETCHED_PROPERTY ) { final Setter setter = attribute.getPropertyAccess().getSetter(); @@ -4574,7 +4577,7 @@ public abstract class AbstractEntityPersister @Override public void setPropertyValue(Object object, String propertyName, Object value) { - final AttributeMapping attributeMapping = (AttributeMapping) findSubPart( propertyName, this ); + final AttributeMapping attributeMapping = findSubPart( propertyName, this ).asAttributeMapping(); final AttributeMetadata attributeMetadata = attributeMapping.getAttributeMetadataAccess().resolveAttributeMetadata( this ); attributeMetadata.getPropertyAccess().getSetter().set( object, value ); } @@ -5690,11 +5693,11 @@ public abstract class AbstractEntityPersister "Could not resolve attribute '%s' of '%s' due to the attribute being declared in multiple sub types: ['%s', '%s']", name, getJavaType().getJavaType().getTypeName(), - ( (AttributeMapping) attribute ).getDeclaringType() + attribute.asAttributeMapping().getDeclaringType() .getJavaType() .getJavaType() .getTypeName(), - ( (AttributeMapping) subDefinedAttribute ).getDeclaringType() + subDefinedAttribute.asAttributeMapping().getDeclaringType() .getJavaType() .getJavaType() .getTypeName() 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 544912548b..5758e526d6 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 @@ -5835,8 +5835,8 @@ public abstract class BaseSqmToSqlAstConverter extends Base if ( type instanceof SqmExpressible) { adjustedTimestampType = (SqmExpressible) type; } - else if (type instanceof AttributeMapping ) { - adjustedTimestampType = (SqmExpressible) ( (AttributeMapping) type ).getMappedType(); + else if (type instanceof ValueMapping ) { + adjustedTimestampType = (SqmExpressible) ( (ValueMapping) type ).getMappedType(); } else { // else we know it has not been transformed diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java index 009a468063..1f13f877c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Fetchable.java @@ -8,6 +8,7 @@ package org.hibernate.sql.results.graph; import org.hibernate.Incubating; import org.hibernate.engine.FetchTiming; +import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.spi.NavigablePath; @@ -67,4 +68,8 @@ public interface Fetchable extends ModelPart { default boolean incrementFetchDepth(){ return false; } + + default AttributeMapping asAttributeMapping() { + return null; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java index a0d15c0628..73003dcbe9 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/AbstractEntityInitializer.java @@ -51,6 +51,7 @@ import org.hibernate.sql.results.graph.AssemblerCreationState; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultAssembler; import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.basic.BasicResultAssembler; import org.hibernate.sql.results.graph.entity.internal.EntityResultInitializer; import org.hibernate.sql.results.internal.NullValueAssembler; @@ -177,7 +178,8 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces final int size = entityDescriptor.getNumberOfFetchables(); for ( int i = 0; i < size; i++ ) { - final AttributeMapping attributeMapping = (AttributeMapping) entityDescriptor.getFetchable( i ); + final Fetchable fetchable = entityDescriptor.getFetchable( i ); + final AttributeMapping attributeMapping = fetchable.asAttributeMapping(); // todo (6.0) : somehow we need to track whether all state is loaded/resolved // note that lazy proxies or uninitialized collections count against // that in the affirmative diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java index b2cf9cd4cc..838d44b73b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/domain/CircularBiDirectionalFetchImpl.java @@ -248,7 +248,7 @@ public class CircularBiDirectionalFetchImpl implements BiDirectionalFetch, Assoc final Initializer parentInitializer = rowProcessingState.resolveInitializer( circularPath ); assert parentInitializer.isCollectionInitializer(); final CollectionInitializer circ = (CollectionInitializer) parentInitializer; - final EntityPersister entityPersister = (EntityPersister) ( (AttributeMapping) fetchable ).getMappedType(); + final EntityPersister entityPersister = (EntityPersister) fetchable.asAttributeMapping().getMappedType(); final CollectionKey collectionKey = circ.resolveCollectionKey( rowProcessingState ); final Object key = collectionKey.getKey(); final SharedSessionContractImplementor session = rowProcessingState.getJdbcValuesSourceProcessingState()