diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java
index b79e372445..3419f3a25e 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java
@@ -11,10 +11,6 @@ import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.Iterator;
-import jakarta.persistence.ManyToMany;
-import jakarta.persistence.OneToOne;
-import jakarta.persistence.metamodel.Attribute;
-import jakarta.persistence.metamodel.Type;
import org.hibernate.AssertionFailure;
import org.hibernate.internal.EntityManagerMessageLogger;
@@ -29,6 +25,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
import org.hibernate.metamodel.AttributeClassification;
import org.hibernate.metamodel.RepresentationMode;
+import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
@@ -52,6 +49,12 @@ import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.EntityType;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
+import org.hibernate.type.spi.CompositeTypeImplementor;
+
+import jakarta.persistence.ManyToMany;
+import jakarta.persistence.OneToOne;
+import jakarta.persistence.metamodel.Attribute;
+import jakarta.persistence.metamodel.Type;
/**
* A factory for building {@link Attribute} instances. Exposes 3 main services for building
@@ -231,21 +234,16 @@ public class AttributeFactory {
final Component component = (Component) typeContext.getHibernateValue();
final EmbeddableTypeImpl embeddableType;
- final EmbeddableRepresentationStrategy representationStrategy = context.getTypeConfiguration()
- .getMetadataBuildingContext()
- .getBuildingOptions()
- .getManagedTypeRepresentationResolver()
- .resolveStrategy( component, context.getRuntimeModelCreationContext() );
-
if ( component.isDynamic() ) {
final JavaType javaTypeDescriptor = context.getJavaTypeDescriptorRegistry().getDescriptor( Map.class );
embeddableType = new EmbeddableTypeImpl<>(
javaTypeDescriptor,
- representationStrategy,
true,
context.getJpaMetamodel()
);
+
+ context.registerComponentByEmbeddable( embeddableType, component );
}
else {
// we should have a non-dynamic embeddable
@@ -263,7 +261,6 @@ public class AttributeFactory {
embeddableType = new EmbeddableTypeImpl<>(
javaTypeDescriptor,
- representationStrategy,
false,
context.getJpaMetamodel()
);
@@ -585,16 +582,23 @@ public class AttributeFactory {
private static final MemberResolver embeddedMemberResolver = (attributeContext, metadataContext) -> {
// the owner is an embeddable
- final EmbeddableDomainType> ownerType = (EmbeddableDomainType) attributeContext.getOwnerType();
+ final EmbeddableDomainType> ownerType = (EmbeddableDomainType>) attributeContext.getOwnerType();
+ final Component ownerBootDescriptor = metadataContext.getEmbeddableBootDescriptor( ownerType );
- if ( ownerType.getRepresentationStrategy().getMode() == RepresentationMode.MAP ) {
+ final CompositeTypeImplementor ownerComponentType = (CompositeTypeImplementor) ownerBootDescriptor.getType();
+ final EmbeddableValuedModelPart ownerMappingModelDescriptor = ownerComponentType.getMappingModelPart();
+ final EmbeddableRepresentationStrategy ownerRepStrategy = ownerMappingModelDescriptor
+ .getEmbeddableTypeDescriptor()
+ .getRepresentationStrategy();
+
+ if ( ownerRepStrategy.getMode() == RepresentationMode.MAP ) {
return new MapMember(
attributeContext.getPropertyMapping().getName(),
attributeContext.getPropertyMapping().getType().getReturnedClass()
);
}
else {
- return ownerType.getRepresentationStrategy()
+ return ownerRepStrategy
.resolvePropertyAccess( attributeContext.getPropertyMapping() )
.getGetter()
.getMember();
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java
index d20ab5e964..8167c3004d 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java
@@ -6,10 +6,12 @@
*/
package org.hibernate.metamodel.internal;
+import java.util.Map;
import java.util.function.Supplier;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.Component;
+import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
/**
@@ -20,12 +22,24 @@ import org.hibernate.metamodel.spi.EmbeddableInstantiator;
public class EmbeddableInstantiatorDynamicMap
extends AbstractDynamicMapInstantiator
implements EmbeddableInstantiator {
- public EmbeddableInstantiatorDynamicMap(Component bootDescriptor) {
+ private final Supplier runtimeDescriptorAccess;
+
+ public EmbeddableInstantiatorDynamicMap(
+ Component bootDescriptor,
+ Supplier runtimeDescriptorAccess) {
super( bootDescriptor.getRoleName() );
+ this.runtimeDescriptorAccess = runtimeDescriptorAccess;
}
@Override
public Object instantiate(Supplier