5555import java .util .function .BiFunction ;
5656
5757import static java .util .Collections .unmodifiableMap ;
58+ import static java .util .stream .Collectors .toSet ;
5859import static org .hibernate .metamodel .internal .InjectionHelper .injectField ;
5960
6061/**
@@ -345,14 +346,16 @@ else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
345346 final MappedSuperclassDomainType <Object > jpaType = (MappedSuperclassDomainType <Object >)
346347 mappedSuperclassByMappedSuperclassMapping .get ( safeMapping );
347348
348- applyIdMetadata ( safeMapping , jpaType );
349+ final Set < String > idProperties = applyIdMetadata ( safeMapping , jpaType );
349350 applyVersionAttribute ( safeMapping , jpaType );
350351// applyNaturalIdAttribute( safeMapping, jpaType );
351352
352353 for ( Property property : safeMapping .getDeclaredProperties () ) {
353- if ( !safeMapping .isVersioned ()
354+ if ( !idProperties .contains ( property .getName () )
355+ // skip already applied properties
356+ && (!safeMapping .isVersioned ()
354357 // skip the version property, it was already handled previously.
355- || property != safeMapping .getVersion () ) {
358+ || property != safeMapping .getVersion ()) ) {
356359 buildAttribute ( property , jpaType );
357360 }
358361 }
@@ -568,7 +571,7 @@ private EmbeddableTypeImpl<?> applyIdClassMetadata(Component idClassComponent) {
568571 return embeddableType ;
569572 }
570573
571- private <X > void applyIdMetadata (MappedSuperclass mappingType , MappedSuperclassDomainType <X > jpaMappingType ) {
574+ private <X > Set < String > applyIdMetadata (MappedSuperclass mappingType , MappedSuperclassDomainType <X > jpaMappingType ) {
572575 @ SuppressWarnings ("unchecked" )
573576 final AttributeContainer <X > attributeContainer = (AttributeContainer <X >) jpaMappingType ;
574577 if ( mappingType .hasIdentifierProperty () ) {
@@ -582,6 +585,7 @@ private <X> void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassD
582585 attributeFactory ::buildIdAttribute
583586 );
584587 attributeContainer .getInFlightAccess ().applyIdAttribute ( attribute );
588+ return Set .of (attribute .getName ());
585589 }
586590 }
587591 //a MappedSuperclass can have no identifier if the id is set below in the hierarchy
@@ -592,7 +596,9 @@ else if ( mappingType.getIdentifierMapper() != null ) {
592596 mappingType .getIdentifierMapper ().getProperties ()
593597 );
594598 attributeContainer .getInFlightAccess ().applyIdClassAttributes ( attributes );
599+ return attributes .stream ().map ( Attribute ::getName ).collect ( toSet ());
595600 }
601+ return Set .of ();
596602 }
597603
598604 private <X > void applyVersionAttribute (PersistentClass persistentClass , EntityDomainType <X > jpaEntityType ) {
0 commit comments