From 7f4a4afd64a2da30183a56cf7d0b1b37af56f0be Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Thu, 10 Mar 2022 13:32:53 +0100 Subject: [PATCH] Also create inverse model parts for nested embeddable attributes --- .../internal/AbstractEmbeddableMapping.java | 16 +++++++++++++--- .../internal/EmbeddedAttributeMapping.java | 17 ----------------- .../internal/MappingModelCreationHelper.java | 2 +- .../VirtualEmbeddedAttributeMapping.java | 18 ------------------ 4 files changed, 14 insertions(+), 39 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java index c60d6bfd9b..bee1e9756a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java @@ -32,6 +32,7 @@ import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMetadata; import org.hibernate.metamodel.mapping.AttributeMetadataAccess; import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.SelectableMapping; @@ -194,9 +195,18 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType attributeMapping = toOne; currentIndex += attributeMapping.getJdbcTypeCount(); } - else if ( attributeMapping instanceof EmbeddedAttributeMapping ) { - attributeMapping = ( (EmbeddedAttributeMapping) attributeMapping ).copy( declaringType ); - currentIndex = attributeMapping.getJdbcTypeCount(); + else if ( attributeMapping instanceof EmbeddableValuedModelPart ) { + final SelectableMapping[] subMappings = new SelectableMapping[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 { throw new UnsupportedMappingException( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java index 29e74a13e9..b17f8af1e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java @@ -354,23 +354,6 @@ public class EmbeddedAttributeMapping 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( String parentInjectionAttributeName, EmbeddableMappingType embeddableMappingType) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index bf55580ff2..70b6f72dd0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -1527,7 +1527,7 @@ public class MappingModelCreationHelper { ); } - public static EmbeddableValuedModelPart createInverseModelPart( + public static EmbeddedAttributeMapping createInverseModelPart( EmbeddableValuedModelPart modelPart, ManagedMappingType keyDeclaringType, TableGroupProducer declaringTableGroupProducer, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualEmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualEmbeddedAttributeMapping.java index d348f05604..4a9956070a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualEmbeddedAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualEmbeddedAttributeMapping.java @@ -8,7 +8,6 @@ package org.hibernate.metamodel.mapping.internal; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; -import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMetadataAccess; import org.hibernate.metamodel.mapping.EmbeddableMappingType; 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() - ); - } }