2222import org .hibernate .annotations .OnDeleteAction ;
2323import org .hibernate .annotations .SqlFragmentAlias ;
2424import org .hibernate .boot .registry .classloading .spi .ClassLoadingException ;
25- import org .hibernate .boot .spi .InFlightMetadataCollector ;
2625import org .hibernate .boot .spi .MetadataBuildingContext ;
2726import org .hibernate .boot .spi .PropertyData ;
2827import org .hibernate .internal .util .collections .ArrayHelper ;
7473import static org .hibernate .models .spi .TypeDetailsHelper .resolveRawClass ;
7574import static org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies .EMBEDDED ;
7675import static org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies .NOOP ;
77- import static org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies .interpret ;
7876
7977/**
8078 * @author Emmanuel Bernard
@@ -268,29 +266,23 @@ private static void registerSyntheticProperty(
268266 String propertyName ,
269267 String syntheticPropertyName ,
270268 MetadataBuildingContext context ) {
269+ final var collector = context .getMetadataCollector ();
271270 if ( value instanceof ToOne toOne ) {
272271 toOne .setReferencedPropertyName ( syntheticPropertyName );
273272 toOne .setReferenceToPrimaryKey ( false );
274- context .getMetadataCollector ().addUniquePropertyReference (
275- ownerEntity .getEntityName (),
276- syntheticPropertyName
277- );
273+ collector .addUniquePropertyReference ( ownerEntity .getEntityName (), syntheticPropertyName );
278274 }
279275 else if ( value instanceof Collection collection ) {
280276 collection .setReferencedPropertyName ( syntheticPropertyName );
281277 //not unique because we could create a mtm wo association table
282- context .getMetadataCollector ().addPropertyReference (
283- ownerEntity .getEntityName (),
284- syntheticPropertyName
285- );
278+ collector .addPropertyReference ( ownerEntity .getEntityName (), syntheticPropertyName );
286279 }
287280 else {
288281 throw new AssertionFailure ( "Property ref on an unexpected Value type: " + value .getClass ().getName () );
289282 }
290283 final String associatedEntityName = associatedClass .getEntityName ();
291284 final String generatedName = inverse ? "inverse__" + associatedEntityName : associatedEntityName ;
292- context .getMetadataCollector ()
293- .addPropertyReferencedAssociation ( generatedName , propertyName , syntheticPropertyName );
285+ collector .addPropertyReferencedAssociation ( generatedName , propertyName , syntheticPropertyName );
294286 }
295287
296288 private static String syntheticPropertyName (
@@ -311,12 +303,9 @@ private static String associationMessage(PersistentClass associatedEntity, Annot
311303 }
312304 else {
313305 final PropertyHolder propertyHolder = joinColumns .getPropertyHolder ();
314- if ( propertyHolder != null ) {
315- return "'" + propertyHolder .getEntityName () + "." + joinColumns .getPropertyName () + "'" ;
316- }
317- else {
318- return "" ;
319- }
306+ return propertyHolder != null
307+ ? "'" + propertyHolder .getEntityName () + "." + joinColumns .getPropertyName () + "'"
308+ : "" ;
320309 }
321310 }
322311
@@ -354,7 +343,7 @@ else if ( persistentClassOrJoin instanceof Join join ) {
354343 result .setUpdateable ( false );
355344 result .setInsertable ( false );
356345 result .setValue ( embeddedComponent );
357- result .setPropertyAccessorName ( "embedded" );
346+ result .setPropertyAccessorName ( EMBEDDED . getExternalName () );
358347 if ( persistentClassOrJoin instanceof Join ) {
359348 // the referenced column is in the joined table, add the synthetic property there
360349 persistentClassOrJoin .addProperty ( result );
@@ -433,10 +422,10 @@ private static List<Property> findPropertiesByColumns(
433422 // specified by the @JoinColumn annotations.
434423 final List <Column > orderedColumns = new ArrayList <>( columns .getJoinColumns ().size () );
435424 final Map <Column , Set <Property >> columnsToProperty = new HashMap <>();
436- final InFlightMetadataCollector collector = context .getMetadataCollector ();
437- for ( AnnotatedJoinColumn joinColumn : columns .getJoinColumns () ) {
425+ final var collector = context .getMetadataCollector ();
426+ for ( var joinColumn : columns .getJoinColumns () ) {
438427 if ( joinColumn .isReferenceImplicit () ) {
439- throw new AnnotationException ("Association " + associationMessage ( associatedEntity , columns )
428+ throw new AnnotationException ( "Association " + associationMessage ( associatedEntity , columns )
440429 + " has a '@JoinColumn' which does not specify the 'referencedColumnName'"
441430 + " (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')" );
442431 }
@@ -554,28 +543,28 @@ else if ( orderedProperties.contains( property ) ) {
554543 }
555544
556545 private static void matchColumnsByProperty (Property property , Map <Column , Set <Property >> columnsToProperty ) {
557- if ( property != null
558- && NOOP != interpret ( property .getPropertyAccessorName () )
559- && EMBEDDED != interpret ( property .getPropertyAccessorName () ) ) {
560- //TODO: we can't return subproperties because the caller
561- // needs top level properties, but this results in
562- // a limitation where I need to be referencing all
563- // columns of an embeddable instead of just some
564- // if ( property.isComposite() ) {
565- // for ( Property sp : ( (Component) property.getValue() ).getProperties() ) {
566- // matchColumnsByProperty( sp, columnsToProperty );
546+ if ( property != null ) {
547+ final String propertyAccessorName = property .getPropertyAccessorName ();
548+ if ( !NOOP .getExternalName ().equals ( propertyAccessorName )
549+ && !EMBEDDED .getExternalName ().equals ( propertyAccessorName ) ) {
550+ //TODO: we can't return subproperties because the caller
551+ // needs top level properties, but this results in
552+ // a limitation where I need to be referencing all
553+ // columns of an embeddable instead of just some
554+ // if ( property.isComposite() ) {
555+ // for ( Property sp : ( (Component) property.getValue() ).getProperties() ) {
556+ // matchColumnsByProperty( sp, columnsToProperty );
557+ // }
567558// }
568- // }
569- // else {
570- for ( Selectable selectable : property .getSelectables () ) {
571- //can be a Formula, so we don't cast
572- //noinspection SuspiciousMethodCalls
573- if ( columnsToProperty .containsKey ( selectable ) ) {
574- //noinspection SuspiciousMethodCalls
575- columnsToProperty .get ( selectable ).add ( property );
559+ // else {
560+ for ( Selectable selectable : property .getSelectables () ) {
561+ if ( selectable instanceof Column column
562+ && columnsToProperty .containsKey ( column ) ) {
563+ columnsToProperty .get ( column ).add ( property );
564+ }
576565 }
566+ // }
577567 }
578- // }
579568 }
580569 }
581570
@@ -597,9 +586,9 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
597586 property = idProperty ;
598587 propertyName = propertyName .substring ( idName .length () + 1 );
599588 }
600- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
601- while ( tokens .hasMoreElements () ) {
602- String element = ( String ) tokens .nextElement ();
589+ final var tokens = new StringTokenizer ( propertyName , "." , false );
590+ while ( tokens .hasMoreTokens () ) {
591+ final String element = tokens .nextToken ();
603592 if ( property == null ) {
604593 property = associatedClass .getProperty ( element );
605594 }
@@ -614,13 +603,13 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin
614603 }
615604 catch ( MappingException e ) {
616605 try {
617- //if we do not find it try to check the identifier mapper
606+ // if we do not find it, try to check the identifier mapper
618607 if ( associatedClass .getIdentifierMapper () == null ) {
619608 return null ;
620609 }
621- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
622- while ( tokens .hasMoreElements () ) {
623- final String element = ( String ) tokens .nextElement ();
610+ final var tokens = new StringTokenizer ( propertyName , "." , false );
611+ while ( tokens .hasMoreTokens () ) {
612+ final String element = tokens .nextToken ();
624613 if ( property == null ) {
625614 property = associatedClass .getIdentifierMapper ().getProperty ( element );
626615 }
@@ -650,9 +639,9 @@ public static Property findPropertyByName(Component component, String propertyNa
650639 return null ;
651640 }
652641 else {
653- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
654- while ( tokens .hasMoreElements () ) {
655- final String element = ( String ) tokens .nextElement ();
642+ final var tokens = new StringTokenizer ( propertyName , "." , false );
643+ while ( tokens .hasMoreTokens () ) {
644+ final String element = tokens .nextToken ();
656645 if ( property == null ) {
657646 property = component .getProperty ( element );
658647 }
@@ -667,13 +656,13 @@ public static Property findPropertyByName(Component component, String propertyNa
667656 }
668657 catch (MappingException e ) {
669658 try {
670- //if we do not find it try to check the identifier mapper
659+ // if we do not find it, try to check the identifier mapper
671660 if ( component .getOwner ().getIdentifierMapper () == null ) {
672661 return null ;
673662 }
674- final StringTokenizer tokens = new StringTokenizer ( propertyName , "." , false );
675- while ( tokens .hasMoreElements () ) {
676- final String element = ( String ) tokens .nextElement ();
663+ final var tokens = new StringTokenizer ( propertyName , "." , false );
664+ while ( tokens .hasMoreTokens () ) {
665+ final String element = tokens .nextToken ();
677666 if ( property == null ) {
678667 property = component .getOwner ().getIdentifierMapper ().getProperty ( element );
679668 }
@@ -722,7 +711,7 @@ public static AttributeContainer findColumnOwner(
722711 PersistentClass persistentClass ,
723712 String columnName ,
724713 MetadataBuildingContext context ) {
725- final InFlightMetadataCollector metadataCollector = context .getMetadataCollector ();
714+ final var metadataCollector = context .getMetadataCollector ();
726715 PersistentClass current = persistentClass ;
727716 while ( current != null ) {
728717 try {
@@ -916,8 +905,7 @@ public static EnumSet<CascadeType> aggregateCascadeTypes(
916905 Cascade cascadeAnnotation ,
917906 boolean orphanRemoval ,
918907 MetadataBuildingContext context ) {
919- final EnumSet <CascadeType > cascades =
920- convertToHibernateCascadeType ( cascadeTypes );
908+ final var cascades = convertToHibernateCascadeType ( cascadeTypes );
921909 final CascadeType [] hibernateCascades =
922910 cascadeAnnotation == null
923911 ? null
@@ -937,7 +925,7 @@ public static EnumSet<CascadeType> aggregateCascadeTypes(
937925 }
938926
939927 private static EnumSet <CascadeType > convertToHibernateCascadeType (jakarta .persistence .CascadeType [] cascades ) {
940- final EnumSet < CascadeType > cascadeTypes = EnumSet .noneOf ( CascadeType .class );
928+ final var cascadeTypes = EnumSet .noneOf ( CascadeType .class );
941929 if ( cascades != null ) {
942930 for ( jakarta .persistence .CascadeType cascade : cascades ) {
943931 cascadeTypes .add ( convertCascadeType ( cascade ) );
@@ -1076,14 +1064,12 @@ public static <A extends Annotation> A extractFromPackage(
10761064// where context.getMetadataCollector() can cache some of this - either the annotations themselves
10771065// or even just the XPackage resolutions
10781066
1079- final String declaringClassName = classDetails .getName ();
1080- final String packageName = qualifier ( declaringClassName );
1067+ final String packageName = qualifier ( classDetails .getName () );
10811068 if ( isEmpty ( packageName ) ) {
10821069 return null ;
10831070 }
10841071 else {
1085- final ModelsContext modelsContext =
1086- context .getBootstrapContext ().getModelsContext ();
1072+ final var modelsContext = context .getBootstrapContext ().getModelsContext ();
10871073 try {
10881074 return modelsContext .getClassDetailsRegistry ()
10891075 .resolveClassDetails ( packageName + ".package-info" )
0 commit comments