HHH-15201 Composite ID with dynamic-map entities fails with an exception

This commit is contained in:
Andrea Boriero 2022-04-29 17:48:53 +02:00
parent 03410ac24e
commit aa6bb1481c
4 changed files with 27 additions and 9 deletions

View File

@ -8,6 +8,8 @@ package org.hibernate.metamodel.mapping;
import org.hibernate.engine.spi.IdentifierValue; import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister;
/** /**
* Describes the mapping of an entity's identifier. * Describes the mapping of an entity's identifier.
@ -41,7 +43,15 @@ public interface EntityIdentifierMapping extends ValueMapping, ModelPart {
Object getIdentifier(Object entity); Object getIdentifier(Object entity);
/**
* @deprecated use {@link #setIdentifier(Object, Object, EntityPersister, SharedSessionContractImplementor)} instead.
*/
@Deprecated
void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session); 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(); Object instantiate();
} }

View File

@ -236,12 +236,16 @@ public class InverseNonAggregatedIdentifierMapping extends EmbeddedAttributeMapp
@Override @Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
final List<AttributeMapping> mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings(); final EntityPersister entityDescriptor = session.getFactory().getRuntimeMetamodels()
final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()];
final SessionFactoryImplementor factory = session.getFactory();
final EntityPersister entityDescriptor = factory.getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( entity.getClass() ); .getEntityDescriptor( entity.getClass() );
setIdentifier( entity, id, entityDescriptor, session );
}
@Override
public void setIdentifier(Object entity, Object id, EntityPersister entityDescriptor, SharedSessionContractImplementor session) {
final List<AttributeMapping> mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings();
final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()];
getEmbeddableTypeDescriptor().forEachAttributeMapping( getEmbeddableTypeDescriptor().forEachAttributeMapping(
(position, attribute) -> { (position, attribute) -> {

View File

@ -256,12 +256,16 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif
@Override @Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
final List<AttributeMapping> mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings(); final EntityPersister entityDescriptor = session.getFactory().getRuntimeMetamodels()
final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()];
final SessionFactoryImplementor factory = session.getFactory();
final EntityPersister entityDescriptor = factory.getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( entity.getClass() ); .getEntityDescriptor( entity.getClass() );
setIdentifier( entity, id, entityDescriptor, session );
}
@Override
public void setIdentifier(Object entity, Object id, EntityPersister entityDescriptor, SharedSessionContractImplementor session) {
final List<AttributeMapping> mappedIdAttributeMappings = identifierValueMapper.getAttributeMappings();
final Object[] propertyValues = new Object[mappedIdAttributeMappings.size()];
getEmbeddableTypeDescriptor().forEachAttributeMapping( getEmbeddableTypeDescriptor().forEachAttributeMapping(
(position, attribute) -> { (position, attribute) -> {

View File

@ -5191,7 +5191,7 @@ public abstract class AbstractEntityPersister
@Override @Override
public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) { public void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session) {
identifierMapping.setIdentifier( entity, id, session ); identifierMapping.setIdentifier( entity, id, this, session );
} }
@Override @Override