55
55
import org .hibernate .annotations .SoftDelete ;
56
56
import org .hibernate .annotations .Subselect ;
57
57
import org .hibernate .annotations .Synchronize ;
58
- import org .hibernate .annotations .Tables ;
59
58
import org .hibernate .annotations .TypeBinderType ;
60
59
import org .hibernate .annotations .View ;
61
60
import org .hibernate .annotations .Where ;
@@ -432,24 +431,8 @@ private void handleIdentifier(
432
431
}
433
432
434
433
private void processComplementaryTableDefinitions () {
435
- annotatedClass .forEachAnnotationUsage ( org .hibernate .annotations .Table .class , getSourceModelContext (), (usage ) -> {
436
- final Table appliedTable = findTable ( usage .appliesTo () );
437
-
438
- final String comment = usage .comment ();
439
- if ( !comment .isEmpty () ) {
440
- appliedTable .setComment ( comment );
441
- }
442
-
443
- final String checkConstraint = usage .checkConstraint ();
444
- if ( !checkConstraint .isEmpty () ) {
445
- //noinspection deprecation
446
- appliedTable .addCheckConstraint ( checkConstraint );
447
- }
448
-
449
- TableBinder .addIndexes ( appliedTable , usage .indexes (), context );
450
- } );
451
-
452
- final jakarta .persistence .Table jpaTableUsage = annotatedClass .getAnnotationUsage ( jakarta .persistence .Table .class , getSourceModelContext () );
434
+ final jakarta .persistence .Table jpaTableUsage =
435
+ annotatedClass .getAnnotationUsage ( jakarta .persistence .Table .class , getSourceModelContext () );
453
436
if ( jpaTableUsage != null ) {
454
437
final Table table = persistentClass .getTable ();
455
438
TableBinder .addJpaIndexes ( table , jpaTableUsage .indexes (), context );
@@ -2061,24 +2044,17 @@ private void bindJoinToPersistentClass(Join join, AnnotatedJoinColumns joinColum
2061
2044
}
2062
2045
2063
2046
private void setForeignKeyNameIfDefined (Join join ) {
2064
- final String tableName = join .getTable ().getQuotedName ();
2065
- final org .hibernate .annotations .Table matchingTable = findMatchingComplementaryTableAnnotation ( tableName );
2066
2047
final SimpleValue key = (SimpleValue ) join .getKey ();
2067
- if ( matchingTable != null && !matchingTable .foreignKey ().name ().isEmpty () ) {
2068
- key .setForeignKeyName ( matchingTable .foreignKey ().name () );
2069
- }
2070
- else {
2071
- final SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable ( join );
2072
- if ( jpaSecondaryTable != null ) {
2073
- final boolean noConstraintByDefault = context .getBuildingOptions ().isNoConstraintByDefault ();
2074
- if ( jpaSecondaryTable .foreignKey ().value () == ConstraintMode .NO_CONSTRAINT
2075
- || jpaSecondaryTable .foreignKey ().value () == ConstraintMode .PROVIDER_DEFAULT && noConstraintByDefault ) {
2076
- key .disableForeignKey ();
2077
- }
2078
- else {
2079
- key .setForeignKeyName ( nullIfEmpty ( jpaSecondaryTable .foreignKey ().name () ) );
2080
- key .setForeignKeyDefinition ( nullIfEmpty ( jpaSecondaryTable .foreignKey ().foreignKeyDefinition () ) );
2081
- }
2048
+ final SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable ( join );
2049
+ if ( jpaSecondaryTable != null ) {
2050
+ final boolean noConstraintByDefault = context .getBuildingOptions ().isNoConstraintByDefault ();
2051
+ if ( jpaSecondaryTable .foreignKey ().value () == ConstraintMode .NO_CONSTRAINT
2052
+ || jpaSecondaryTable .foreignKey ().value () == ConstraintMode .PROVIDER_DEFAULT && noConstraintByDefault ) {
2053
+ key .disableForeignKey ();
2054
+ }
2055
+ else {
2056
+ key .setForeignKeyName ( nullIfEmpty ( jpaSecondaryTable .foreignKey ().name () ) );
2057
+ key .setForeignKeyDefinition ( nullIfEmpty ( jpaSecondaryTable .foreignKey ().foreignKeyDefinition () ) );
2082
2058
}
2083
2059
}
2084
2060
}
@@ -2101,24 +2077,6 @@ private SecondaryTable findMatchingSecondaryTable(Join join) {
2101
2077
return null ;
2102
2078
}
2103
2079
2104
- private org .hibernate .annotations .Table findMatchingComplementaryTableAnnotation (String tableName ) {
2105
- final org .hibernate .annotations .Table table = annotatedClass .getDirectAnnotationUsage ( org .hibernate .annotations .Table .class );
2106
- if ( table != null && tableName .equals ( table .appliesTo () ) ) {
2107
- return table ;
2108
- }
2109
- else {
2110
- final Tables tables = annotatedClass .getAnnotationUsage ( Tables .class , getSourceModelContext () );
2111
- if ( tables != null ) {
2112
- for (org .hibernate .annotations .Table nested : tables .value ()) {
2113
- if ( tableName .equals ( nested .appliesTo () ) ) {
2114
- return nested ;
2115
- }
2116
- }
2117
- }
2118
- return null ;
2119
- }
2120
- }
2121
-
2122
2080
private SecondaryRow findMatchingSecondaryRowAnnotation (String tableName ) {
2123
2081
final SecondaryRow row = annotatedClass .getDirectAnnotationUsage ( SecondaryRow .class );
2124
2082
if ( row != null && ( row .table ().isEmpty () || tableName .equals ( row .table () ) ) ) {
@@ -2263,16 +2221,11 @@ Join createJoin(
2263
2221
2264
2222
private void handleSecondaryRowManagement (Join join ) {
2265
2223
final String tableName = join .getTable ().getQuotedName ();
2266
- final org .hibernate .annotations .Table matchingTable = findMatchingComplementaryTableAnnotation ( tableName );
2267
2224
final SecondaryRow matchingRow = findMatchingSecondaryRowAnnotation ( tableName );
2268
2225
if ( matchingRow != null ) {
2269
2226
join .setInverse ( !matchingRow .owned () );
2270
2227
join .setOptional ( matchingRow .optional () );
2271
2228
}
2272
- else if ( matchingTable != null ) {
2273
- join .setInverse ( matchingTable .inverse () );
2274
- join .setOptional ( matchingTable .optional () );
2275
- }
2276
2229
else {
2277
2230
//default
2278
2231
join .setInverse ( false );
@@ -2282,8 +2235,6 @@ else if ( matchingTable != null ) {
2282
2235
2283
2236
private void processSecondaryTableCustomSql (Join join ) {
2284
2237
final String tableName = join .getTable ().getQuotedName ();
2285
- final org .hibernate .annotations .Table matchingTable = findMatchingComplementaryTableAnnotation ( tableName );
2286
-
2287
2238
final SQLInsert sqlInsert = resolveCustomSqlAnnotation ( annotatedClass , SQLInsert .class , tableName );
2288
2239
if ( sqlInsert != null ) {
2289
2240
join .setCustomSQLInsert (
@@ -2296,17 +2247,6 @@ private void processSecondaryTableCustomSql(Join join) {
2296
2247
join .setInsertExpectation ( getDefaultSupplier ( expectationClass ) );
2297
2248
}
2298
2249
}
2299
- else if ( matchingTable != null ) {
2300
- final SQLInsert matchingTableInsert = matchingTable .sqlInsert ();
2301
- final String matchingTableInsertSql = matchingTableInsert .sql ().trim ();
2302
- if ( !matchingTableInsertSql .isEmpty () ) {
2303
- join .setCustomSQLInsert (
2304
- matchingTableInsertSql ,
2305
- matchingTableInsert .callable (),
2306
- fromResultCheckStyle ( matchingTableInsert .check () )
2307
- );
2308
- }
2309
- }
2310
2250
2311
2251
final SQLUpdate sqlUpdate = resolveCustomSqlAnnotation ( annotatedClass , SQLUpdate .class , tableName );
2312
2252
if ( sqlUpdate != null ) {
@@ -2320,17 +2260,6 @@ else if ( matchingTable != null ) {
2320
2260
join .setUpdateExpectation ( getDefaultSupplier ( expectationClass ) );
2321
2261
}
2322
2262
}
2323
- else if ( matchingTable != null ) {
2324
- final SQLUpdate matchingTableUpdate = matchingTable .sqlUpdate ();
2325
- final String matchingTableUpdateSql = matchingTableUpdate .sql ().trim ();
2326
- if ( !matchingTableUpdateSql .isEmpty () ) {
2327
- join .setCustomSQLUpdate (
2328
- matchingTableUpdateSql ,
2329
- matchingTableUpdate .callable (),
2330
- fromResultCheckStyle ( matchingTableUpdate .check () )
2331
- );
2332
- }
2333
- }
2334
2263
2335
2264
final SQLDelete sqlDelete = resolveCustomSqlAnnotation ( annotatedClass , SQLDelete .class , tableName );
2336
2265
if ( sqlDelete != null ) {
@@ -2344,17 +2273,6 @@ else if ( matchingTable != null ) {
2344
2273
join .setDeleteExpectation ( getDefaultSupplier ( expectationClass ) );
2345
2274
}
2346
2275
}
2347
- else if ( matchingTable != null ) {
2348
- final SQLDelete matchingTableDelete = matchingTable .sqlDelete ();
2349
- final String deleteSql = matchingTableDelete .sql ().trim ();
2350
- if ( !deleteSql .isEmpty () ) {
2351
- join .setCustomSQLDelete (
2352
- deleteSql ,
2353
- matchingTableDelete .callable (),
2354
- fromResultCheckStyle ( matchingTableDelete .check () )
2355
- );
2356
- }
2357
- }
2358
2276
}
2359
2277
2360
2278
public java .util .Map <String , Join > getSecondaryTables () {
@@ -2378,24 +2296,6 @@ public void setIgnoreIdAnnotations(boolean ignoreIdAnnotations) {
2378
2296
this .ignoreIdAnnotations = ignoreIdAnnotations ;
2379
2297
}
2380
2298
2381
- private Table findTable (String tableName ) {
2382
- for ( Table table : persistentClass .getTableClosure () ) {
2383
- if ( table .getQuotedName ().equals ( tableName ) ) {
2384
- //we are in the correct table to find columns
2385
- return table ;
2386
- }
2387
- }
2388
- //maybe a join/secondary table
2389
- for ( Join join : secondaryTables .values () ) {
2390
- if ( join .getTable ().getQuotedName ().equals ( tableName ) ) {
2391
- return join .getTable ();
2392
- }
2393
- }
2394
- throw new AnnotationException ( "Entity '" + name
2395
- + "' has a '@org.hibernate.annotations.Table' annotation which 'appliesTo' an unknown table named '"
2396
- + tableName + "'" );
2397
- }
2398
-
2399
2299
public AccessType getPropertyAccessType () {
2400
2300
return propertyAccessType ;
2401
2301
}
0 commit comments