From aa6bb1481caeee6c690dce5494a6edc04265cf8a Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 29 Apr 2022 17:48:53 +0200 Subject: [PATCH] HHH-15201 Composite ID with dynamic-map entities fails with an exception --- .../metamodel/mapping/EntityIdentifierMapping.java | 10 ++++++++++ .../InverseNonAggregatedIdentifierMapping.java | 12 ++++++++---- .../internal/NonAggregatedIdentifierMappingImpl.java | 12 ++++++++---- .../persister/entity/AbstractEntityPersister.java | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java index 8fbec564d2..ee883cea48 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EntityIdentifierMapping.java @@ -8,6 +8,8 @@ package org.hibernate.metamodel.mapping; import org.hibernate.engine.spi.IdentifierValue; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.persister.entity.EntityPersister; + /** * Describes the mapping of an entity's identifier. @@ -41,7 +43,15 @@ public interface EntityIdentifierMapping extends ValueMapping, ModelPart { Object getIdentifier(Object entity); + /** + * @deprecated use {@link #setIdentifier(Object, Object, EntityPersister, SharedSessionContractImplementor)} instead. + */ + @Deprecated void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session); + default void setIdentifier(Object entity, Object id, EntityPersister entityDescriptor, SharedSessionContractImplementor session){ + setIdentifier( entity, id, session ); + } + Object instantiate(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java index fe536eb0d7..22a0457bb7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/InverseNonAggregatedIdentifierMapping.java @@ -236,12 +236,16 @@ public class InverseNonAggregatedIdentifierMapping extends EmbeddedAttributeMapp @Override public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { - final List mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings(); - final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()]; - final SessionFactoryImplementor factory = session.getFactory(); - final EntityPersister entityDescriptor = factory.getRuntimeMetamodels() + final EntityPersister entityDescriptor = session.getFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor( entity.getClass() ); + setIdentifier( entity, id, entityDescriptor, session ); + } + + @Override + public void setIdentifier(Object entity, Object id, EntityPersister entityDescriptor, SharedSessionContractImplementor session) { + final List mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings(); + final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()]; getEmbeddableTypeDescriptor().forEachAttributeMapping( (position, attribute) -> { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java index b3e2893f7b..d4756d56aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java @@ -256,12 +256,16 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif @Override public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { - final List mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings(); - final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()]; - final SessionFactoryImplementor factory = session.getFactory(); - final EntityPersister entityDescriptor = factory.getRuntimeMetamodels() + final EntityPersister entityDescriptor = session.getFactory().getRuntimeMetamodels() .getMappingMetamodel() .getEntityDescriptor( entity.getClass() ); + setIdentifier( entity, id, entityDescriptor, session ); + } + + @Override + public void setIdentifier(Object entity, Object id, EntityPersister entityDescriptor, SharedSessionContractImplementor session) { + final List mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings(); + final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()]; getEmbeddableTypeDescriptor().forEachAttributeMapping( (position, attribute) -> { 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 0f0f48edde..91f3aab361 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 @@ -5191,7 +5191,7 @@ public abstract class AbstractEntityPersister @Override public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { - identifierMapping.setIdentifier( entity, id, session ); + identifierMapping.setIdentifier( entity, id, this, session ); } @Override