150
150
import org .jboss .logging .Logger ;
151
151
152
152
import static jakarta .persistence .AccessType .PROPERTY ;
153
+ import static jakarta .persistence .FetchType .EAGER ;
154
+ import static jakarta .persistence .FetchType .LAZY ;
153
155
import static org .hibernate .cfg .AnnotatedColumn .buildColumnFromAnnotation ;
154
156
import static org .hibernate .cfg .AnnotatedColumn .buildColumnFromNoAnnotation ;
155
157
import static org .hibernate .cfg .AnnotatedColumn .buildColumnsFromAnnotations ;
@@ -1465,11 +1467,16 @@ else if ( fetch.value() == org.hibernate.annotations.FetchMode.SUBSELECT ) {
1465
1467
private void handleLazy (FetchType jpaFetchType ) {
1466
1468
final LazyCollection lazy = property .getAnnotation ( LazyCollection .class );
1467
1469
if ( lazy != null ) {
1468
- collection .setLazy ( lazy .value () != LazyCollectionOption .FALSE );
1469
- collection .setExtraLazy ( lazy .value () == LazyCollectionOption .EXTRA );
1470
+ boolean lazyFalse = lazy .value () == LazyCollectionOption .FALSE ;
1471
+ if ( jpaFetchType == EAGER && !lazyFalse ) {
1472
+ throw new AnnotationException ("Collection '" + safeCollectionRole ()
1473
+ + "' is marked 'fetch=EAGER' and '@LazyCollection(" + lazy .value () + ")'" );
1474
+ }
1475
+ collection .setLazy ( !lazyFalse );
1476
+ collection .setExtraLazy ( lazy .value () == LazyCollectionOption .EXTRA );
1470
1477
}
1471
1478
else {
1472
- collection .setLazy ( jpaFetchType == FetchType . LAZY );
1479
+ collection .setLazy ( jpaFetchType == LAZY );
1473
1480
collection .setExtraLazy ( false );
1474
1481
}
1475
1482
}
@@ -1489,7 +1496,7 @@ else if ( elementCollection != null ) {
1489
1496
return elementCollection .fetch ();
1490
1497
}
1491
1498
else if ( manyToAny != null ) {
1492
- return FetchType . LAZY ;
1499
+ return LAZY ;
1493
1500
}
1494
1501
else {
1495
1502
throw new AssertionFailure (
@@ -2357,7 +2364,7 @@ private void handleManyToAny(
2357
2364
inverseJoinColumns ,
2358
2365
inferredData ,
2359
2366
cascadeDeleteEnabled ,
2360
- anyAnn .fetch () == FetchType . LAZY ,
2367
+ anyAnn .fetch () == LAZY ,
2361
2368
Nullability .NO_CONSTRAINT ,
2362
2369
propertyHolder ,
2363
2370
new EntityBinder (),
0 commit comments