89
89
import org .hibernate .metamodel .mapping .internal .SqlTypedMappingImpl ;
90
90
import org .hibernate .metamodel .mapping .internal .ToOneAttributeMapping ;
91
91
import org .hibernate .metamodel .mapping .ordering .OrderByFragment ;
92
+ import org .hibernate .sql .results .graph .collection .internal .EagerCollectionFetch ;
93
+ import org .hibernate .type .descriptor .converter .internal .OrdinalEnumValueConverter ;
94
+ import org .hibernate .type .descriptor .converter .spi .BasicValueConverter ;
92
95
import org .hibernate .metamodel .model .domain .BasicDomainType ;
93
96
import org .hibernate .metamodel .model .domain .EmbeddableDomainType ;
94
97
import org .hibernate .metamodel .model .domain .EntityDomainType ;
389
392
import org .hibernate .type .EnumType ;
390
393
import org .hibernate .type .JavaObjectType ;
391
394
import org .hibernate .type .SqlTypes ;
392
- import org .hibernate .type .descriptor .converter .internal .OrdinalEnumValueConverter ;
393
- import org .hibernate .type .descriptor .converter .spi .BasicValueConverter ;
394
395
import org .hibernate .type .descriptor .java .EnumJavaType ;
395
396
import org .hibernate .type .descriptor .java .JavaType ;
396
397
import org .hibernate .type .descriptor .java .JavaTypeHelper ;
@@ -7283,7 +7284,6 @@ else if ( getLoadQueryInfluencers().hasEnabledFetchProfiles() ) {
7283
7284
fetchable ,
7284
7285
fetchTiming ,
7285
7286
joined ,
7286
- explicitFetch ,
7287
7287
alias
7288
7288
);
7289
7289
@@ -7335,6 +7335,55 @@ public ImmutableFetchList visitNestedFetches(FetchParent fetchParent) {
7335
7335
7336
7336
@ Override
7337
7337
public ImmutableFetchList visitFetches (FetchParent fetchParent ) {
7338
+ if ( fetchParent instanceof EagerCollectionFetch ) {
7339
+ final EagerCollectionFetch collectionFetch = (EagerCollectionFetch ) fetchParent ;
7340
+ final PluralAttributeMapping pluralAttributeMapping = collectionFetch .getFetchedMapping ();
7341
+ final NavigablePath fetchablePath = collectionFetch .getNavigablePath ();
7342
+
7343
+ final TableGroup tableGroup = getFromClauseIndex ().getTableGroup ( fetchablePath );
7344
+
7345
+ // Base restrictions have already been applied if this is an explicit fetch
7346
+ if ( getFromClauseIndex ().findFetchedJoinByPath ( fetchablePath ) == null ) {
7347
+ final Restrictable restrictable = pluralAttributeMapping
7348
+ .getCollectionDescriptor ()
7349
+ .getCollectionType ()
7350
+ .getAssociatedJoinable ( getCreationContext ().getSessionFactory () );
7351
+ restrictable .applyBaseRestrictions (
7352
+ (predicate ) -> addCollectionFilterPredicate ( tableGroup .getNavigablePath (), predicate ),
7353
+ tableGroup ,
7354
+ true ,
7355
+ getLoadQueryInfluencers ().getEnabledFilters (),
7356
+ null ,
7357
+ this
7358
+ );
7359
+ }
7360
+
7361
+ pluralAttributeMapping .applyBaseManyToManyRestrictions (
7362
+ (predicate ) -> {
7363
+ final TableGroup parentTableGroup = getFromClauseIndex ().getTableGroup ( collectionFetch .getFetchParent ().getNavigablePath () );
7364
+ TableGroupJoin pluralTableGroupJoin = null ;
7365
+ for ( TableGroupJoin nestedTableGroupJoin : parentTableGroup .getTableGroupJoins () ) {
7366
+ if ( nestedTableGroupJoin .getNavigablePath () == fetchablePath ) {
7367
+ pluralTableGroupJoin = nestedTableGroupJoin ;
7368
+ break ;
7369
+ }
7370
+ }
7371
+
7372
+ assert pluralTableGroupJoin != null ;
7373
+ pluralTableGroupJoin .applyPredicate ( predicate );
7374
+ },
7375
+ tableGroup ,
7376
+ true ,
7377
+ getLoadQueryInfluencers ().getEnabledFilters (),
7378
+ null ,
7379
+ this
7380
+ );
7381
+
7382
+ if ( currentQuerySpec ().isRoot () ) {
7383
+ assert tableGroup .getModelPart () == pluralAttributeMapping ;
7384
+ applyOrdering ( tableGroup , pluralAttributeMapping );
7385
+ }
7386
+ }
7338
7387
final FetchableContainer referencedMappingContainer = fetchParent .getReferencedMappingContainer ();
7339
7388
final int keySize = referencedMappingContainer .getNumberOfKeyFetchables ();
7340
7389
final int size = referencedMappingContainer .getNumberOfFetchables ();
@@ -7381,7 +7430,6 @@ private Fetch buildFetch(
7381
7430
Fetchable fetchable ,
7382
7431
FetchTiming fetchTiming ,
7383
7432
boolean joined ,
7384
- boolean explicitFetch ,
7385
7433
String alias ) {
7386
7434
// fetch has access to its parent in addition to the parent having its fetches.
7387
7435
//
@@ -7390,65 +7438,14 @@ private Fetch buildFetch(
7390
7438
// "initializing" state as part of AfterLoadAction
7391
7439
7392
7440
try {
7393
- final Fetch fetch = fetchParent .generateFetchableFetch (
7441
+ return fetchParent .generateFetchableFetch (
7394
7442
fetchable ,
7395
7443
fetchablePath ,
7396
7444
fetchTiming ,
7397
7445
joined ,
7398
7446
alias ,
7399
7447
this
7400
7448
);
7401
-
7402
- if ( fetchable instanceof PluralAttributeMapping
7403
- && fetch .getTiming () == FetchTiming .IMMEDIATE
7404
- && joined ) {
7405
- final TableGroup tableGroup = getFromClauseIndex ().getTableGroup ( fetchablePath );
7406
- final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping ) fetchable ;
7407
-
7408
- // Base restrictions have already been applied if this is an explicit fetch
7409
- if ( !explicitFetch ) {
7410
- final Restrictable restrictable = pluralAttributeMapping
7411
- .getCollectionDescriptor ()
7412
- .getCollectionType ()
7413
- .getAssociatedJoinable ( getCreationContext ().getSessionFactory () );
7414
- restrictable .applyBaseRestrictions (
7415
- (predicate ) -> addCollectionFilterPredicate ( tableGroup .getNavigablePath (), predicate ),
7416
- tableGroup ,
7417
- true ,
7418
- getLoadQueryInfluencers ().getEnabledFilters (),
7419
- null ,
7420
- this
7421
- );
7422
- }
7423
-
7424
- pluralAttributeMapping .applyBaseManyToManyRestrictions (
7425
- (predicate ) -> {
7426
- final TableGroup parentTableGroup = getFromClauseIndex ().getTableGroup ( fetchParent .getNavigablePath () );
7427
- TableGroupJoin pluralTableGroupJoin = null ;
7428
- for ( TableGroupJoin nestedTableGroupJoin : parentTableGroup .getTableGroupJoins () ) {
7429
- if ( nestedTableGroupJoin .getNavigablePath () == fetchablePath ) {
7430
- pluralTableGroupJoin = nestedTableGroupJoin ;
7431
- break ;
7432
- }
7433
- }
7434
-
7435
- assert pluralTableGroupJoin != null ;
7436
- pluralTableGroupJoin .applyPredicate ( predicate );
7437
- },
7438
- tableGroup ,
7439
- true ,
7440
- getLoadQueryInfluencers ().getEnabledFilters (),
7441
- null ,
7442
- this
7443
- );
7444
-
7445
- if ( currentQuerySpec ().isRoot () ) {
7446
- assert tableGroup .getModelPart () == pluralAttributeMapping ;
7447
- applyOrdering ( tableGroup , pluralAttributeMapping );
7448
- }
7449
- }
7450
-
7451
- return fetch ;
7452
7449
}
7453
7450
catch (RuntimeException e ) {
7454
7451
throw new HibernateException (
0 commit comments