37
37
38
38
import jakarta .persistence .JoinColumn ;
39
39
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 ;
40
43
import static org .hibernate .boot .model .internal .BinderHelper .findReferencedColumnOwner ;
41
44
import 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 ;
42
50
import static org .hibernate .internal .util .StringHelper .isBlank ;
43
51
import static org .hibernate .internal .util .StringHelper .isNotBlank ;
44
52
import static org .hibernate .internal .util .StringHelper .isQuoted ;
@@ -94,7 +102,7 @@ public static AnnotatedJoinColumns buildJoinColumnsOrFormulas(
94
102
AnnotatedJoinColumn .buildJoinFormula ( formula , parent );
95
103
}
96
104
else {
97
- AnnotatedJoinColumn . buildJoinColumn ( column , mappedBy , parent , propertyHolder , inferredData );
105
+ buildJoinColumn ( column , mappedBy , parent , propertyHolder , inferredData );
98
106
}
99
107
}
100
108
@@ -169,7 +177,7 @@ public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix(
169
177
parent .setPropertyName ( getRelativePath ( propertyHolder , propertyName ) );
170
178
parent .setMappedBy ( mappedBy );
171
179
if ( isEmpty ( actualColumns ) ) {
172
- AnnotatedJoinColumn . buildJoinColumn (
180
+ buildJoinColumn (
173
181
null ,
174
182
mappedBy ,
175
183
parent ,
@@ -181,7 +189,7 @@ public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix(
181
189
else {
182
190
parent .setMappedBy ( mappedBy );
183
191
for ( var actualColumn : actualColumns ) {
184
- AnnotatedJoinColumn . buildJoinColumn (
192
+ buildJoinColumn (
185
193
actualColumn ,
186
194
mappedBy ,
187
195
parent ,
@@ -212,11 +220,11 @@ public static AnnotatedJoinColumns buildJoinTableJoinColumns(
212
220
parent .setPropertyName ( getRelativePath ( propertyHolder , inferredData .getPropertyName () ) );
213
221
parent .setMappedBy ( mappedBy );
214
222
if ( joinColumns == null ) {
215
- AnnotatedJoinColumn . buildImplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData );
223
+ buildImplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData );
216
224
}
217
225
else {
218
226
for ( var joinColumn : joinColumns ) {
219
- AnnotatedJoinColumn . buildExplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData , joinColumn );
227
+ buildExplicitJoinTableJoinColumn ( parent , propertyHolder , inferredData , joinColumn );
220
228
}
221
229
}
222
230
handlePropertyRef ( inferredData .getAttributeMember (), parent );
@@ -228,11 +236,11 @@ Property resolveMapsId() {
228
236
final var identifier = persistentClass .getIdentifier ();
229
237
try {
230
238
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
233
241
}
234
242
catch (MappingException me ) {
235
- throw new AnnotationException ( "Identifier field '" + getMapsId ()
243
+ throw new AnnotationException ( "Identifier field '" + mapsId
236
244
+ "' named in '@MapsId' does not exist in entity '" + persistentClass .getEntityName () + "'" ,
237
245
me );
238
246
}
@@ -318,7 +326,7 @@ public void setMappedBy(String entityName, String logicalTableName, String mappe
318
326
*/
319
327
public ForeignKeyType getReferencedColumnsType (PersistentClass referencedEntity ) {
320
328
if ( referencedProperty != null ) {
321
- return ForeignKeyType . NON_PRIMARY_KEY_REFERENCE ;
329
+ return NON_PRIMARY_KEY_REFERENCE ;
322
330
}
323
331
324
332
if ( columns .isEmpty () ) {
@@ -341,7 +349,7 @@ public ForeignKeyType getReferencedColumnsType(PersistentClass referencedEntity)
341
349
throw new FailedSecondPassException ( me .getMessage (), me );
342
350
}
343
351
}
344
- final Table table = table ( columnOwner );
352
+ final var table = table ( columnOwner );
345
353
// final List<Selectable> keyColumns = referencedEntity.getKey().getSelectables();
346
354
final var keyColumns =
347
355
table .getPrimaryKey () == null
@@ -353,17 +361,17 @@ public ForeignKeyType getReferencedColumnsType(PersistentClass referencedEntity)
353
361
explicitColumnReference = true ;
354
362
if ( !keyColumns .contains ( column ( context , table , column .getReferencedColumn () ) ) ) {
355
363
// we have a column which does not belong to the PK
356
- return ForeignKeyType . NON_PRIMARY_KEY_REFERENCE ;
364
+ return NON_PRIMARY_KEY_REFERENCE ;
357
365
}
358
366
}
359
367
}
360
368
if ( explicitColumnReference ) {
361
369
// if we got to here, all the columns belong to the PK
362
370
return keyColumns .size () == columns .size ()
363
371
// we have all the PK columns
364
- ? ForeignKeyType . EXPLICIT_PRIMARY_KEY_REFERENCE
372
+ ? EXPLICIT_PRIMARY_KEY_REFERENCE
365
373
// we have a subset of the PK columns
366
- : ForeignKeyType . NON_PRIMARY_KEY_REFERENCE ;
374
+ : NON_PRIMARY_KEY_REFERENCE ;
367
375
}
368
376
else {
369
377
// there were no nonempty referencedColumnNames
@@ -395,8 +403,9 @@ private static Column column(MetadataBuildingContext context, Table table, Strin
395
403
}
396
404
397
405
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 ();
400
409
final var database = collector .getDatabase ();
401
410
final var jdbcEnvironment = database .getJdbcEnvironment ();
402
411
final Identifier columnIdentifier = columnIdentifier (
@@ -464,9 +473,10 @@ public Identifier getReferencedPrimaryKeyColumnName() {
464
473
465
474
private Identifier handleElement (Identifier columnIdentifier ) {
466
475
// 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}_" ) ) {
468
478
return Identifier .toIdentifier (
469
- columnIdentifier . getText () .replace ( "_{element}_" , "_" ),
479
+ identifierText .replace ( "_{element}_" , "_" ),
470
480
columnIdentifier .isQuoted ()
471
481
);
472
482
}
@@ -502,13 +512,13 @@ private boolean isMappedBySide() {
502
512
503
513
private ImplicitJoinColumnNameSource .Nature getImplicitNature () {
504
514
if ( getPropertyHolder ().isEntity () ) {
505
- return ImplicitJoinColumnNameSource . Nature . ENTITY ;
515
+ return ENTITY ;
506
516
}
507
517
else if ( isElementCollection () ) {
508
- return ImplicitJoinColumnNameSource . Nature . ELEMENT_COLLECTION ;
518
+ return ELEMENT_COLLECTION ;
509
519
}
510
520
else {
511
- return ImplicitJoinColumnNameSource . Nature . ENTITY_COLLECTION ;
521
+ return ENTITY_COLLECTION ;
512
522
}
513
523
}
514
524
@@ -589,7 +599,7 @@ public Identifier getReferencedColumnName() {
589
599
return null ;
590
600
}
591
601
592
- final Property mappedByProperty =
602
+ final var mappedByProperty =
593
603
collector .getEntityBinding ( getMappedByEntityName () )
594
604
.getProperty ( getMappedByPropertyName () );
595
605
final var value = (SimpleValue ) mappedByProperty .getValue ();
0 commit comments