From 2e583d556d2dc11f1e854dad72ca6e9b95991e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Cedomir=20Igaly?= Date: Sun, 1 Dec 2024 07:51:41 +0100 Subject: [PATCH] HHH-18868 ID and version properties are handled separately, do not process them twice --- .../metamodel/internal/MetadataContext.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 02276925ac..18ebbf2cd9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -55,6 +55,7 @@ import java.util.Set; import java.util.function.BiFunction; import static java.util.Collections.unmodifiableMap; +import static java.util.stream.Collectors.toSet; import static org.hibernate.metamodel.internal.InjectionHelper.injectField; /** @@ -345,14 +346,16 @@ public class MetadataContext { final MappedSuperclassDomainType jpaType = (MappedSuperclassDomainType) mappedSuperclassByMappedSuperclassMapping.get( safeMapping ); - applyIdMetadata( safeMapping, jpaType ); + final Set idProperties = applyIdMetadata( safeMapping, jpaType ); applyVersionAttribute( safeMapping, jpaType ); // applyNaturalIdAttribute( safeMapping, jpaType ); for ( Property property : safeMapping.getDeclaredProperties() ) { - if ( !safeMapping.isVersioned() + if ( !idProperties.contains( property.getName() ) + // skip already applied properties + && (!safeMapping.isVersioned() // skip the version property, it was already handled previously. - || property != safeMapping.getVersion() ) { + || property != safeMapping.getVersion()) ) { buildAttribute( property, jpaType ); } } @@ -568,7 +571,7 @@ public class MetadataContext { return embeddableType; } - private void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassDomainType jpaMappingType) { + private Set applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassDomainType jpaMappingType) { @SuppressWarnings("unchecked") final AttributeContainer attributeContainer = (AttributeContainer) jpaMappingType; if ( mappingType.hasIdentifierProperty() ) { @@ -582,6 +585,7 @@ public class MetadataContext { attributeFactory::buildIdAttribute ); attributeContainer.getInFlightAccess().applyIdAttribute( attribute ); + return Set.of(attribute.getName()); } } //a MappedSuperclass can have no identifier if the id is set below in the hierarchy @@ -592,7 +596,9 @@ public class MetadataContext { mappingType.getIdentifierMapper().getProperties() ); attributeContainer.getInFlightAccess().applyIdClassAttributes( attributes ); + return attributes.stream().map( Attribute::getName ).collect( toSet()); } + return Set.of(); } private void applyVersionAttribute(PersistentClass persistentClass, EntityDomainType jpaEntityType) {