28
28
import org .hibernate .boot .spi .MetadataBuildingContext ;
29
29
import org .hibernate .boot .spi .PropertyData ;
30
30
import org .hibernate .internal .CoreMessageLogger ;
31
- import org .hibernate .mapping .AggregateColumn ;
32
31
import org .hibernate .mapping .BasicValue ;
33
32
import org .hibernate .mapping .Component ;
34
33
import org .hibernate .mapping .Property ;
66
65
import static org .hibernate .boot .model .internal .BinderHelper .getPropertyOverriddenByMapperOrMapsId ;
67
66
import static org .hibernate .boot .model .internal .BinderHelper .getRelativePath ;
68
67
import static org .hibernate .boot .model .internal .BinderHelper .hasToOneAnnotation ;
69
- import static org .hibernate .boot .model .internal .BinderHelper .isGlobalGeneratorNameGlobal ;
70
- import static org .hibernate .boot .model .internal .GeneratorBinder .buildGenerators ;
71
- import static org .hibernate .boot .model .internal .GeneratorBinder .generatorType ;
72
- import static org .hibernate .boot .model .internal .GeneratorBinder .makeIdGenerator ;
73
68
import static org .hibernate .boot .model .internal .HCANNHelper .findContainingAnnotations ;
74
69
import static org .hibernate .boot .model .internal .PropertyBinder .addElementsOfClass ;
75
70
import static org .hibernate .boot .model .internal .PropertyBinder .processElementAnnotations ;
71
+ import static org .hibernate .boot .model .internal .PropertyBinder .processId ;
76
72
import static org .hibernate .boot .model .internal .PropertyHolderBuilder .buildPropertyHolder ;
77
73
import static org .hibernate .internal .CoreLogging .messageLogger ;
78
74
import static org .hibernate .internal .util .StringHelper .isEmpty ;
79
75
import static org .hibernate .internal .util .StringHelper .qualify ;
80
76
import static org .hibernate .internal .util .StringHelper .unqualify ;
81
- import static org .hibernate .mapping .SimpleValue .DEFAULT_ID_GEN_STRATEGY ;
82
77
83
78
/**
84
79
* A binder responsible for interpreting {@link Embeddable} classes and producing
@@ -452,18 +447,27 @@ static Component fillEmbeddable(
452
447
inheritanceStatePerClass
453
448
);
454
449
455
- final XProperty property = propertyAnnotatedElement .getProperty ();
456
- if ( property .isAnnotationPresent ( GeneratedValue .class ) ) {
457
- if ( isIdClass || subholder .isOrWithinEmbeddedId () ) {
458
- processGeneratedId ( context , component , property );
459
- }
460
- else {
461
- throw new AnnotationException (
462
- "Property '" + property .getName () + "' of '"
463
- + getPath ( propertyHolder , inferredData )
464
- + "' is annotated '@GeneratedValue' but is not part of an identifier" );
450
+ final XProperty member = propertyAnnotatedElement .getProperty ();
451
+ if ( isIdClass || subholder .isOrWithinEmbeddedId () ) {
452
+ final Property property = findProperty ( component , member .getName () );
453
+ if ( property != null ) {
454
+ // Identifier properties are always simple values
455
+ final SimpleValue value = (SimpleValue ) property .getValue ();
456
+ processId (
457
+ subholder ,
458
+ propertyAnnotatedElement ,
459
+ value ,
460
+ Map .of (),
461
+ context
462
+ );
465
463
}
466
464
}
465
+ else if ( member .isAnnotationPresent ( GeneratedValue .class ) ) {
466
+ throw new AnnotationException (
467
+ "Property '" + member .getName () + "' of '"
468
+ + getPath ( propertyHolder , inferredData )
469
+ + "' is annotated '@GeneratedValue' but is not part of an identifier" );
470
+ }
467
471
}
468
472
469
473
if ( compositeUserType != null ) {
@@ -473,6 +477,15 @@ static Component fillEmbeddable(
473
477
return component ;
474
478
}
475
479
480
+ private static Property findProperty (Component component , String name ) {
481
+ for ( Property property : component .getProperties () ) {
482
+ if ( property .getName ().equals ( name ) ) {
483
+ return property ;
484
+ }
485
+ }
486
+ return null ;
487
+ }
488
+
476
489
private static CompositeUserType <?> compositeUserType (
477
490
Class <? extends CompositeUserType <?>> compositeUserTypeClass ,
478
491
MetadataBuildingContext context ) {
@@ -782,40 +795,6 @@ private static boolean hasTriggeringAnnotation(XAnnotatedElement property) {
782
795
|| property .isAnnotationPresent (ManyToMany .class );
783
796
}
784
797
785
- private static void processGeneratedId (MetadataBuildingContext context , Component component , XProperty property ) {
786
- final GeneratedValue generatedValue = property .getAnnotation ( GeneratedValue .class );
787
- final String generatorType = generatedValue != null
788
- ? generatorType ( generatedValue , property .getType (), context )
789
- : DEFAULT_ID_GEN_STRATEGY ;
790
- final String generator = generatedValue != null ? generatedValue .generator () : "" ;
791
-
792
- if ( isGlobalGeneratorNameGlobal ( context ) ) {
793
- buildGenerators ( property , context );
794
- context .getMetadataCollector ().addSecondPass ( new IdGeneratorResolverSecondPass (
795
- (SimpleValue ) component .getProperty ( property .getName () ).getValue (),
796
- property ,
797
- generatorType ,
798
- generator ,
799
- context
800
- ) );
801
-
802
- // handleTypeDescriptorRegistrations( property, context );
803
- // bindEmbeddableInstantiatorRegistrations( property, context );
804
- // bindCompositeUserTypeRegistrations( property, context );
805
- // handleConverterRegistrations( property, context );
806
- }
807
- else {
808
- makeIdGenerator (
809
- (SimpleValue ) component .getProperty ( property .getName () ).getValue (),
810
- property ,
811
- generatorType ,
812
- generator ,
813
- context ,
814
- new HashMap <>( buildGenerators ( property , context ) )
815
- );
816
- }
817
- }
818
-
819
798
private static void processIdClassElements (
820
799
PropertyHolder propertyHolder ,
821
800
PropertyData baseInferredData ,
0 commit comments