3737
3838import jakarta .persistence .JoinColumn ;
3939
40+ import static org .hibernate .boot .model .internal .AnnotatedJoinColumn .buildExplicitJoinTableJoinColumn ;
41+ import static org .hibernate .boot .model .internal .AnnotatedJoinColumn .buildImplicitJoinTableJoinColumn ;
42+ import static org .hibernate .boot .model .internal .AnnotatedJoinColumn .buildJoinColumn ;
4043import static org .hibernate .boot .model .internal .BinderHelper .findReferencedColumnOwner ;
4144import static org .hibernate .boot .model .internal .BinderHelper .getRelativePath ;
45+ import static org .hibernate .boot .model .internal .ForeignKeyType .EXPLICIT_PRIMARY_KEY_REFERENCE ;
46+ import static org .hibernate .boot .model .internal .ForeignKeyType .NON_PRIMARY_KEY_REFERENCE ;
47+ import static org .hibernate .boot .model .naming .ImplicitJoinColumnNameSource .Nature .ELEMENT_COLLECTION ;
48+ import static org .hibernate .boot .model .naming .ImplicitJoinColumnNameSource .Nature .ENTITY ;
49+ import static org .hibernate .boot .model .naming .ImplicitJoinColumnNameSource .Nature .ENTITY_COLLECTION ;
4250import static org .hibernate .internal .util .StringHelper .isBlank ;
4351import static org .hibernate .internal .util .StringHelper .isNotBlank ;
4452import static org .hibernate .internal .util .StringHelper .isQuoted ;
@@ -94,7 +102,7 @@ public static AnnotatedJoinColumns buildJoinColumnsOrFormulas(
94102 AnnotatedJoinColumn .buildJoinFormula ( formula , parent );
95103 }
96104 else {
97- AnnotatedJoinColumn . buildJoinColumn ( column , mappedBy , parent , propertyHolder , inferredData );
105+ buildJoinColumn ( column , mappedBy , parent , propertyHolder , inferredData );
98106 }
99107 }
100108
@@ -169,7 +177,7 @@ public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix(
169177 parent .setPropertyName ( getRelativePath ( propertyHolder , propertyName ) );
170178 parent .setMappedBy ( mappedBy );
171179 if ( isEmpty ( actualColumns ) ) {
172- AnnotatedJoinColumn . buildJoinColumn (
180+ buildJoinColumn (
173181 null ,
174182 mappedBy ,
175183 parent ,
@@ -181,7 +189,7 @@ public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix(
181189 else {
182190 parent .setMappedBy ( mappedBy );
183191 for ( var actualColumn : actualColumns ) {
184- AnnotatedJoinColumn . buildJoinColumn (
192+ buildJoinColumn (
185193 actualColumn ,
186194 mappedBy ,
187195 parent ,
@@ -212,11 +220,11 @@ public static AnnotatedJoinColumns buildJoinTableJoinColumns(
212220 parent .setPropertyName ( getRelativePath ( propertyHolder , inferredData .getPropertyName () ) );
213221 parent .setMappedBy ( mappedBy );
214222 if ( joinColumns == null ) {
215- AnnotatedJoinColumn . buildImplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData );
223+ buildImplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData );
216224 }
217225 else {
218226 for ( var joinColumn : joinColumns ) {
219- AnnotatedJoinColumn . buildExplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData , joinColumn );
227+ buildExplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData , joinColumn );
220228 }
221229 }
222230 handlePropertyRef ( inferredData .getAttributeMember (), parent );
@@ -228,11 +236,11 @@ Property resolveMapsId() {
228236 final var identifier = persistentClass .getIdentifier ();
229237 try {
230238 return identifier instanceof Component embeddedIdType
231- ? embeddedIdType .getProperty ( getMapsId () ) // an @EmbeddedId
232- : persistentClass .getProperty ( getMapsId () ); // a simple id or an @IdClass
239+ ? embeddedIdType .getProperty ( mapsId ) // an @EmbeddedId
240+ : persistentClass .getProperty ( mapsId ); // a simple id or an @IdClass
233241 }
234242 catch (MappingException me ) {
235- throw new AnnotationException ( "Identifier field '" + getMapsId ()
243+ throw new AnnotationException ( "Identifier field '" + mapsId
236244 + "' named in '@MapsId' does not exist in entity '" + persistentClass .getEntityName () + "'" ,
237245 me );
238246 }
@@ -318,7 +326,7 @@ public void setMappedBy(String entityName, String logicalTableName, String mappe
318326 */
319327 public ForeignKeyType getReferencedColumnsType (PersistentClass referencedEntity ) {
320328 if ( referencedProperty != null ) {
321- return ForeignKeyType . NON_PRIMARY_KEY_REFERENCE ;
329+ return NON_PRIMARY_KEY_REFERENCE ;
322330 }
323331
324332 if ( columns .isEmpty () ) {
@@ -341,7 +349,7 @@ public ForeignKeyType getReferencedColumnsType(PersistentClass referencedEntity)
341349 throw new FailedSecondPassException ( me .getMessage (), me );
342350 }
343351 }
344- final Table table = table ( columnOwner );
352+ final var table = table ( columnOwner );
345353// final List<Selectable> keyColumns = referencedEntity.getKey().getSelectables();
346354 final var keyColumns =
347355 table .getPrimaryKey () == null
@@ -353,17 +361,17 @@ public ForeignKeyType getReferencedColumnsType(PersistentClass referencedEntity)
353361 explicitColumnReference = true ;
354362 if ( !keyColumns .contains ( column ( context , table , column .getReferencedColumn () ) ) ) {
355363 // we have a column which does not belong to the PK
356- return ForeignKeyType . NON_PRIMARY_KEY_REFERENCE ;
364+ return NON_PRIMARY_KEY_REFERENCE ;
357365 }
358366 }
359367 }
360368 if ( explicitColumnReference ) {
361369 // if we got to here, all the columns belong to the PK
362370 return keyColumns .size () == columns .size ()
363371 // we have all the PK columns
364- ? ForeignKeyType . EXPLICIT_PRIMARY_KEY_REFERENCE
372+ ? EXPLICIT_PRIMARY_KEY_REFERENCE
365373 // we have a subset of the PK columns
366- : ForeignKeyType . NON_PRIMARY_KEY_REFERENCE ;
374+ : NON_PRIMARY_KEY_REFERENCE ;
367375 }
368376 else {
369377 // there were no nonempty referencedColumnNames
@@ -395,8 +403,9 @@ private static Column column(MetadataBuildingContext context, Table table, Strin
395403 }
396404
397405 String buildDefaultColumnName (PersistentClass referencedEntity , String logicalReferencedColumn ) {
398- final var options = getBuildingContext ().getBuildingOptions ();
399- final var collector = getBuildingContext ().getMetadataCollector ();
406+ final var context = getBuildingContext ();
407+ final var options = context .getBuildingOptions ();
408+ final var collector = context .getMetadataCollector ();
400409 final var database = collector .getDatabase ();
401410 final var jdbcEnvironment = database .getJdbcEnvironment ();
402411 final Identifier columnIdentifier = columnIdentifier (
@@ -464,9 +473,10 @@ public Identifier getReferencedPrimaryKeyColumnName() {
464473
465474 private Identifier handleElement (Identifier columnIdentifier ) {
466475 // HHH-11826 magic. See AnnotatedColumn and the HHH-6005 comments
467- if ( columnIdentifier .getText ().contains ( "_{element}_" ) ) {
476+ final String identifierText = columnIdentifier .getText ();
477+ if ( identifierText .contains ( "_{element}_" ) ) {
468478 return Identifier .toIdentifier (
469- columnIdentifier . getText () .replace ( "_{element}_" , "_" ),
479+ identifierText .replace ( "_{element}_" , "_" ),
470480 columnIdentifier .isQuoted ()
471481 );
472482 }
@@ -502,13 +512,13 @@ private boolean isMappedBySide() {
502512
503513 private ImplicitJoinColumnNameSource .Nature getImplicitNature () {
504514 if ( getPropertyHolder ().isEntity () ) {
505- return ImplicitJoinColumnNameSource . Nature . ENTITY ;
515+ return ENTITY ;
506516 }
507517 else if ( isElementCollection () ) {
508- return ImplicitJoinColumnNameSource . Nature . ELEMENT_COLLECTION ;
518+ return ELEMENT_COLLECTION ;
509519 }
510520 else {
511- return ImplicitJoinColumnNameSource . Nature . ENTITY_COLLECTION ;
521+ return ENTITY_COLLECTION ;
512522 }
513523 }
514524
@@ -589,7 +599,7 @@ public Identifier getReferencedColumnName() {
589599 return null ;
590600 }
591601
592- final Property mappedByProperty =
602+ final var mappedByProperty =
593603 collector .getEntityBinding ( getMappedByEntityName () )
594604 .getProperty ( getMappedByPropertyName () );
595605 final var value = (SimpleValue ) mappedByProperty .getValue ();
0 commit comments