Also create inverse model parts for nested embeddable attributes

This commit is contained in:
Christian Beikov 2022-03-10 13:32:53 +01:00
parent c548a79f0b
commit 7f4a4afd64
4 changed files with 14 additions and 39 deletions

View File

@ -32,6 +32,7 @@ import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadata; import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess; import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.SelectableMapping;
@ -194,9 +195,18 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
attributeMapping = toOne; attributeMapping = toOne;
currentIndex += attributeMapping.getJdbcTypeCount(); currentIndex += attributeMapping.getJdbcTypeCount();
} }
else if ( attributeMapping instanceof EmbeddedAttributeMapping ) { else if ( attributeMapping instanceof EmbeddableValuedModelPart ) {
attributeMapping = ( (EmbeddedAttributeMapping) attributeMapping ).copy( declaringType ); final SelectableMapping[] subMappings = new SelectableMapping[attributeMapping.getJdbcTypeCount()];
currentIndex = attributeMapping.getJdbcTypeCount(); for (int i = 0; i < subMappings.length; i++) {
subMappings[i] = selectableMappings.getSelectable( currentIndex++ );
}
attributeMapping = MappingModelCreationHelper.createInverseModelPart(
(EmbeddableValuedModelPart) attributeMapping,
declaringType,
declaringTableGroupProducer,
new SelectableMappingsImpl( subMappings ),
creationProcess
);
} }
else { else {
throw new UnsupportedMappingException( throw new UnsupportedMappingException(

View File

@ -354,23 +354,6 @@ public class EmbeddedAttributeMapping
return "EmbeddedAttributeMapping(" + navigableRole + ")@" + System.identityHashCode( this ); return "EmbeddedAttributeMapping(" + navigableRole + ")@" + System.identityHashCode( this );
} }
public AttributeMapping copy(ManagedMappingType declaringType) {
return new EmbeddedAttributeMapping(
getAttributeName(),
getNavigableRole(),
getStateArrayPosition(),
tableExpression,
getAttributeMetadataAccess(),
getParentInjectionAttributePropertyAccess(),
getTiming(),
getStyle(),
getEmbeddableTypeDescriptor(),
declaringType,
getPropertyAccess(),
getValueGeneration()
);
}
private static PropertyAccess getPropertyAccess( private static PropertyAccess getPropertyAccess(
String parentInjectionAttributeName, String parentInjectionAttributeName,
EmbeddableMappingType embeddableMappingType) { EmbeddableMappingType embeddableMappingType) {

View File

@ -1527,7 +1527,7 @@ public class MappingModelCreationHelper {
); );
} }
public static EmbeddableValuedModelPart createInverseModelPart( public static EmbeddedAttributeMapping createInverseModelPart(
EmbeddableValuedModelPart modelPart, EmbeddableValuedModelPart modelPart,
ManagedMappingType keyDeclaringType, ManagedMappingType keyDeclaringType,
TableGroupProducer declaringTableGroupProducer, TableGroupProducer declaringTableGroupProducer,

View File

@ -8,7 +8,6 @@ package org.hibernate.metamodel.mapping.internal;
import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming; import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadataAccess; import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
@ -99,21 +98,4 @@ public class VirtualEmbeddedAttributeMapping extends EmbeddedAttributeMapping im
); );
} }
@Override
public AttributeMapping copy(ManagedMappingType declaringType) {
return new VirtualEmbeddedAttributeMapping(
getAttributeName(),
getNavigableRole(),
getStateArrayPosition(),
getContainingTableExpression(),
getAttributeMetadataAccess(),
getParentInjectionAttributePropertyAccess(),
getTiming(),
getStyle(),
getEmbeddableTypeDescriptor(),
declaringType,
getPropertyAccess(),
getValueGeneration()
);
}
} }