8989import java .util .Iterator ;
9090import java .util .List ;
9191import java .util .Map ;
92+ import java .util .Objects ;
9293import java .util .Set ;
9394
9495import static jakarta .persistence .InheritanceType .SINGLE_TABLE ;
118119import static org .hibernate .internal .CoreLogging .messageLogger ;
119120import static org .hibernate .internal .util .ReflectHelper .getDefaultSupplier ;
120121import static org .hibernate .internal .util .StringHelper .isBlank ;
121- import static org .hibernate .internal .util .StringHelper .isEmpty ;
122122import static org .hibernate .internal .util .StringHelper .isNotBlank ;
123123import static org .hibernate .internal .util .StringHelper .nullIfEmpty ;
124124import static org .hibernate .internal .util .StringHelper .unqualify ;
@@ -143,8 +143,6 @@ public class EntityBinder {
143143 private String name ;
144144 private ClassDetails annotatedClass ;
145145 private PersistentClass persistentClass ;
146- private boolean lazy ;
147- private ClassDetails proxyClass ;
148146 private String where ;
149147 // todo : we should defer to InFlightMetadataCollector.EntityTableXref for secondary table tracking;
150148 // atm we use both from here; HBM binding solely uses InFlightMetadataCollector.EntityTableXref
@@ -1259,9 +1257,8 @@ private void bindEntity() {
12591257 bindEntityAnnotation ();
12601258 bindRowManagement ();
12611259 bindOptimisticLocking ();
1262- bindProxy ();
12631260 bindConcreteProxy ();
1264- bindWhere ();
1261+ bindSqlRestriction ();
12651262 bindCache ();
12661263 bindNaturalIdCache ();
12671264 bindFiltersInHierarchy ();
@@ -1271,11 +1268,9 @@ private void bindEntity() {
12711268 persistentClass .setJpaEntityName ( name );
12721269 persistentClass .setEntityName ( annotatedClass .getName () );
12731270 persistentClass .setCached ( isCached );
1274- persistentClass .setLazy ( lazy );
1271+ persistentClass .setLazy ( true );
12751272 persistentClass .setQueryCacheLayout ( queryCacheLayout );
1276- if ( proxyClass != null && proxyClass != ClassDetails .VOID_CLASS_DETAILS ) {
1277- persistentClass .setProxyInterfaceName ( proxyClass .getName () );
1278- }
1273+ persistentClass .setProxyInterfaceName ( annotatedClass .getName () );
12791274
12801275 if ( persistentClass instanceof RootClass ) {
12811276 bindRootEntity ();
@@ -1435,21 +1430,16 @@ private <A extends Annotation> A resolveCustomSqlAnnotation(
14351430 annotatedClass .getRepeatedAnnotationUsages ( overrideAnnotation , modelsContext () );
14361431 if ( isNotEmpty ( dialectOverrides ) ) {
14371432 final Dialect dialect = getMetadataCollector ().getDatabase ().getDialect ();
1438- for ( int i = 0 ; i < dialectOverrides . length ; i ++ ) {
1433+ for ( Annotation annotation : dialectOverrides ) {
14391434 //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+ }
14531443 }
14541444 }
14551445 }
@@ -1568,12 +1558,6 @@ private void bindDiscriminatorValue() {
15681558 }
15691559 }
15701560
1571- private void bindProxy () {
1572- //needed to allow association lazy loading.
1573- lazy = true ;
1574- proxyClass = annotatedClass ;
1575- }
1576-
15771561 private void bindConcreteProxy () {
15781562 final ConcreteProxy annotationUsage =
15791563 annotatedClass .getAnnotationUsage ( ConcreteProxy .class , modelsContext () );
@@ -1586,19 +1570,20 @@ private void bindConcreteProxy() {
15861570 }
15871571 }
15881572
1589- private void bindWhere () {
1590- final SQLRestriction restriction = extractSQLRestriction ( annotatedClass , context );
1573+ private void bindSqlRestriction () {
1574+ final SQLRestriction restriction = extractSQLRestriction ( annotatedClass );
15911575 if ( restriction != null ) {
1592- this . where = restriction .value ();
1576+ where = restriction .value ();
15931577 }
15941578 }
15951579
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 ();
15981582 final SQLRestriction fromClass = getOverridableAnnotation ( classDetails , SQLRestriction .class , context );
15991583 if ( fromClass != null ) {
16001584 return fromClass ;
16011585 }
1586+ // as a special favor to users, we allow @SQLRestriction to be declared on a @MappedSuperclass
16021587 ClassDetails classToCheck = classDetails .getSuperClass ();
16031588 while ( classToCheck != null
16041589 && classToCheck .hasAnnotationUsage ( jakarta .persistence .MappedSuperclass .class , modelsContext ) ) {
0 commit comments