|
68 | 68 | import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath; |
69 | 69 | import static org.hibernate.boot.model.internal.BinderHelper.hasToOneAnnotation; |
70 | 70 | import static org.hibernate.boot.model.internal.HCANNHelper.findContainingAnnotations; |
| 71 | +import static org.hibernate.boot.model.internal.InheritanceState.getSuperclassInheritanceState; |
71 | 72 | import static org.hibernate.boot.model.internal.PropertyBinder.addElementsOfClass; |
72 | 73 | import static org.hibernate.boot.model.internal.PropertyBinder.processElementAnnotations; |
73 | 74 | import static org.hibernate.boot.model.internal.PropertyBinder.processId; |
@@ -393,6 +394,14 @@ static Component fillEmbeddable( |
393 | 394 | context |
394 | 395 | ); |
395 | 396 | } |
| 397 | + else { |
| 398 | + // We need to register ancestor @MappedSuperclass metadata even for embedded types of classes |
| 399 | + // that are not annotated as @Embeddable (i.e. that don't have an inheritance state) |
| 400 | + final var superState = getSuperclassInheritanceState( returnedClassOrElement, inheritanceStatePerClass ); |
| 401 | + if ( superState != null && superState.isEmbeddableSuperclass() ) { |
| 402 | + superState.postProcess( component ); |
| 403 | + } |
| 404 | + } |
396 | 405 |
|
397 | 406 | final XClass annotatedClass = inferredData.getPropertyClass(); |
398 | 407 | final Map<String, String> subclassToSuperclass = component.isPolymorphic() ? new HashMap<>() : null; |
@@ -510,19 +519,19 @@ private static void bindDiscriminator( |
510 | 519 | PropertyData propertyData, |
511 | 520 | InheritanceState inheritanceState, |
512 | 521 | MetadataBuildingContext context) { |
513 | | - if ( inheritanceState == null ) { |
514 | | - return; |
515 | | - } |
516 | | - final AnnotatedDiscriminatorColumn discriminatorColumn = processEmbeddableDiscriminatorProperties( |
517 | | - componentClass, |
518 | | - propertyData, |
519 | | - parentHolder, |
520 | | - holder, |
521 | | - inheritanceState, |
522 | | - context |
523 | | - ); |
524 | | - if ( discriminatorColumn != null ) { |
525 | | - bindDiscriminatorColumnToComponent( component, discriminatorColumn, holder, context ); |
| 522 | + // Discriminated inheritance only applies to explicit @Embeddable types |
| 523 | + if ( !inheritanceState.isEmbeddableSuperclass()) { |
| 524 | + final AnnotatedDiscriminatorColumn discriminatorColumn = processEmbeddableDiscriminatorProperties( |
| 525 | + componentClass, |
| 526 | + propertyData, |
| 527 | + parentHolder, |
| 528 | + holder, |
| 529 | + inheritanceState, |
| 530 | + context |
| 531 | + ); |
| 532 | + if ( discriminatorColumn != null ) { |
| 533 | + bindDiscriminatorColumnToComponent( component, discriminatorColumn, holder, context ); |
| 534 | + } |
526 | 535 | } |
527 | 536 | } |
528 | 537 |
|
|
0 commit comments