5555import java .util .function .BiFunction ;
5656
5757import static java .util .Collections .unmodifiableMap ;
58- import static java .util .stream .Collectors .toSet ;
5958import static org .hibernate .metamodel .internal .InjectionHelper .injectField ;
6059
6160/**
@@ -346,18 +345,22 @@ else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
346345 final MappedSuperclassDomainType <Object > jpaType = (MappedSuperclassDomainType <Object >)
347346 mappedSuperclassByMappedSuperclassMapping .get ( safeMapping );
348347
349- final Set < String > idProperties = applyIdMetadata ( safeMapping , jpaType );
348+ applyIdMetadata ( safeMapping , jpaType );
350349 applyVersionAttribute ( safeMapping , jpaType );
351350// applyNaturalIdAttribute( safeMapping, jpaType );
352351
353352 for ( Property property : safeMapping .getDeclaredProperties () ) {
354- if ( !idProperties .contains ( property .getName () )
355- // skip already applied properties
356- && (!safeMapping .isVersioned ()
357- // skip the version property, it was already handled previously.
358- || property != safeMapping .getVersion ()) ) {
359- buildAttribute ( property , jpaType );
353+ if ( isIdentifierProperty ( property , safeMapping ) ) {
354+ // property represents special handling for id-class mappings but we have already
355+ // accounted for the embedded property mappings in #applyIdMetadata &&
356+ // #buildIdClassAttributes
357+ continue ;
358+ }
359+ if ( safeMapping .isVersioned () && property == safeMapping .getVersion () ) {
360+ // skip the version property, it was already handled previously.
361+ continue ;
360362 }
363+ buildAttribute ( property , jpaType );
361364 }
362365
363366 ( (AttributeContainer <?>) jpaType ).getInFlightAccess ().finishUp ();
@@ -409,6 +412,13 @@ else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
409412 }
410413 }
411414
415+ private static boolean isIdentifierProperty (Property property , MappedSuperclass mappedSuperclass ) {
416+ final Component identifierMapper = mappedSuperclass .getIdentifierMapper ();
417+ return identifierMapper != null &&
418+ identifierMapper .getProperties ().stream ()
419+ .map ( Property ::getName ).anyMatch ( property .getName ()::equals );
420+ }
421+
412422 private <T > void addAttribute (EmbeddableDomainType <T > embeddable , Property property , Component component ) {
413423 final PersistentAttribute <T , ?> attribute =
414424 attributeFactory .buildAttribute ( embeddable , property );
@@ -571,7 +581,7 @@ private EmbeddableTypeImpl<?> applyIdClassMetadata(Component idClassComponent) {
571581 return embeddableType ;
572582 }
573583
574- private <X > Set < String > applyIdMetadata (MappedSuperclass mappingType , MappedSuperclassDomainType <X > jpaMappingType ) {
584+ private <X > void applyIdMetadata (MappedSuperclass mappingType , MappedSuperclassDomainType <X > jpaMappingType ) {
575585 @ SuppressWarnings ("unchecked" )
576586 final AttributeContainer <X > attributeContainer = (AttributeContainer <X >) jpaMappingType ;
577587 if ( mappingType .hasIdentifierProperty () ) {
@@ -585,7 +595,6 @@ private <X> Set<String> applyIdMetadata(MappedSuperclass mappingType, MappedSupe
585595 attributeFactory ::buildIdAttribute
586596 );
587597 attributeContainer .getInFlightAccess ().applyIdAttribute ( attribute );
588- return Set .of (attribute .getName ());
589598 }
590599 }
591600 //a MappedSuperclass can have no identifier if the id is set below in the hierarchy
@@ -596,9 +605,7 @@ else if ( mappingType.getIdentifierMapper() != null ) {
596605 mappingType .getIdentifierMapper ().getProperties ()
597606 );
598607 attributeContainer .getInFlightAccess ().applyIdClassAttributes ( attributes );
599- return attributes .stream ().map ( Attribute ::getName ).collect ( toSet ());
600608 }
601- return Set .of ();
602609 }
603610
604611 private <X > void applyVersionAttribute (PersistentClass persistentClass , EntityDomainType <X > jpaEntityType ) {
0 commit comments