HHH-15811 Avoid secondary super-type cache pollution when casting to AttributeMapping

This commit is contained in:
Sanne Grinovero 2022-12-03 22:15:17 +00:00 committed by Sanne Grinovero
parent a7c3455274
commit d383042229
8 changed files with 35 additions and 15 deletions

View File

@ -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()

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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()

View File

@ -5835,8 +5835,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> 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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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()