89
89
import java .util .Iterator ;
90
90
import java .util .List ;
91
91
import java .util .Map ;
92
+ import java .util .Objects ;
92
93
import java .util .Set ;
93
94
94
95
import static jakarta .persistence .InheritanceType .SINGLE_TABLE ;
118
119
import static org .hibernate .internal .CoreLogging .messageLogger ;
119
120
import static org .hibernate .internal .util .ReflectHelper .getDefaultSupplier ;
120
121
import static org .hibernate .internal .util .StringHelper .isBlank ;
121
- import static org .hibernate .internal .util .StringHelper .isEmpty ;
122
122
import static org .hibernate .internal .util .StringHelper .isNotBlank ;
123
123
import static org .hibernate .internal .util .StringHelper .nullIfEmpty ;
124
124
import static org .hibernate .internal .util .StringHelper .unqualify ;
@@ -143,8 +143,6 @@ public class EntityBinder {
143
143
private String name ;
144
144
private ClassDetails annotatedClass ;
145
145
private PersistentClass persistentClass ;
146
- private boolean lazy ;
147
- private ClassDetails proxyClass ;
148
146
private String where ;
149
147
// todo : we should defer to InFlightMetadataCollector.EntityTableXref for secondary table tracking;
150
148
// atm we use both from here; HBM binding solely uses InFlightMetadataCollector.EntityTableXref
@@ -1259,9 +1257,8 @@ private void bindEntity() {
1259
1257
bindEntityAnnotation ();
1260
1258
bindRowManagement ();
1261
1259
bindOptimisticLocking ();
1262
- bindProxy ();
1263
1260
bindConcreteProxy ();
1264
- bindWhere ();
1261
+ bindSqlRestriction ();
1265
1262
bindCache ();
1266
1263
bindNaturalIdCache ();
1267
1264
bindFiltersInHierarchy ();
@@ -1271,11 +1268,9 @@ private void bindEntity() {
1271
1268
persistentClass .setJpaEntityName ( name );
1272
1269
persistentClass .setEntityName ( annotatedClass .getName () );
1273
1270
persistentClass .setCached ( isCached );
1274
- persistentClass .setLazy ( lazy );
1271
+ persistentClass .setLazy ( true );
1275
1272
persistentClass .setQueryCacheLayout ( queryCacheLayout );
1276
- if ( proxyClass != null && proxyClass != ClassDetails .VOID_CLASS_DETAILS ) {
1277
- persistentClass .setProxyInterfaceName ( proxyClass .getName () );
1278
- }
1273
+ persistentClass .setProxyInterfaceName ( annotatedClass .getName () );
1279
1274
1280
1275
if ( persistentClass instanceof RootClass ) {
1281
1276
bindRootEntity ();
@@ -1435,21 +1430,16 @@ private <A extends Annotation> A resolveCustomSqlAnnotation(
1435
1430
annotatedClass .getRepeatedAnnotationUsages ( overrideAnnotation , modelsContext () );
1436
1431
if ( isNotEmpty ( dialectOverrides ) ) {
1437
1432
final Dialect dialect = getMetadataCollector ().getDatabase ().getDialect ();
1438
- for ( int i = 0 ; i < dialectOverrides . length ; i ++ ) {
1433
+ for ( Annotation annotation : dialectOverrides ) {
1439
1434
//noinspection unchecked
1440
- final DialectOverrider <A > dialectOverride = (DialectOverrider <A >) dialectOverrides [i ];
1441
- if ( !dialectOverride .matches ( dialect ) ) {
1442
- continue ;
1443
- }
1444
-
1445
- final A override = dialectOverride .override ();
1446
- if ( isBlank ( tableName )
1447
- && isEmpty ( ( (CustomSqlDetails ) override ).table () ) ) {
1448
- return override ;
1449
- }
1450
- else if ( isNotBlank ( tableName )
1451
- && tableName .equals ( ( (CustomSqlDetails ) override ).table () ) ) {
1452
- return override ;
1435
+ final DialectOverrider <A > dialectOverride = (DialectOverrider <A >) annotation ;
1436
+ if ( dialectOverride .matches ( dialect ) ) {
1437
+ final A override = dialectOverride .override ();
1438
+ final String table = ((CustomSqlDetails ) override ).table ();
1439
+ if ( isBlank ( tableName ) && isBlank ( table )
1440
+ || Objects .equals ( tableName , table ) ) {
1441
+ return override ;
1442
+ }
1453
1443
}
1454
1444
}
1455
1445
}
@@ -1568,12 +1558,6 @@ private void bindDiscriminatorValue() {
1568
1558
}
1569
1559
}
1570
1560
1571
- private void bindProxy () {
1572
- //needed to allow association lazy loading.
1573
- lazy = true ;
1574
- proxyClass = annotatedClass ;
1575
- }
1576
-
1577
1561
private void bindConcreteProxy () {
1578
1562
final ConcreteProxy annotationUsage =
1579
1563
annotatedClass .getAnnotationUsage ( ConcreteProxy .class , modelsContext () );
@@ -1586,19 +1570,20 @@ private void bindConcreteProxy() {
1586
1570
}
1587
1571
}
1588
1572
1589
- private void bindWhere () {
1590
- final SQLRestriction restriction = extractSQLRestriction ( annotatedClass , context );
1573
+ private void bindSqlRestriction () {
1574
+ final SQLRestriction restriction = extractSQLRestriction ( annotatedClass );
1591
1575
if ( restriction != null ) {
1592
- this . where = restriction .value ();
1576
+ where = restriction .value ();
1593
1577
}
1594
1578
}
1595
1579
1596
- private static SQLRestriction extractSQLRestriction (ClassDetails classDetails , MetadataBuildingContext context ) {
1597
- final SourceModelBuildingContext modelsContext = context . getBootstrapContext (). getModelsContext ();
1580
+ private SQLRestriction extractSQLRestriction (ClassDetails classDetails ) {
1581
+ final SourceModelBuildingContext modelsContext = modelsContext ();
1598
1582
final SQLRestriction fromClass = getOverridableAnnotation ( classDetails , SQLRestriction .class , context );
1599
1583
if ( fromClass != null ) {
1600
1584
return fromClass ;
1601
1585
}
1586
+ // as a special favor to users, we allow @SQLRestriction to be declared on a @MappedSuperclass
1602
1587
ClassDetails classToCheck = classDetails .getSuperClass ();
1603
1588
while ( classToCheck != null
1604
1589
&& classToCheck .hasAnnotationUsage ( jakarta .persistence .MappedSuperclass .class , modelsContext ) ) {
0 commit comments