Fix issue determining fetchablePath and fetchParent for PluralAttributes in LoaderSelectBuilder#createFetchableConsumer() method
This commit is contained in:
parent
d34353e2a3
commit
9633345dbb
|
@ -397,86 +397,65 @@ public class LoaderSelectBuilder {
|
|||
QuerySpec querySpec,
|
||||
LoaderSqlAstCreationState creationState, List<Fetch> fetches) {
|
||||
return fetchable -> {
|
||||
final NavigablePath fetchablePath;
|
||||
final Fetchable fetchedFetchable;
|
||||
if ( fetchable instanceof PluralAttributeMapping ) {
|
||||
fetchablePath = fetchParent.getNavigablePath()
|
||||
.append( fetchable.getFetchableName() )
|
||||
.append( CollectionPart.Nature.ELEMENT.getName() );
|
||||
fetchedFetchable = ( (PluralAttributeMapping) fetchable ).getElementDescriptor();
|
||||
}
|
||||
else {
|
||||
fetchablePath = fetchParent.getNavigablePath().append( fetchable.getFetchableName() );
|
||||
fetchedFetchable = fetchable;
|
||||
}
|
||||
|
||||
final Fetch biDirectionalFetch = fetchedFetchable.resolveCircularFetch(
|
||||
fetchablePath,
|
||||
fetchParent,
|
||||
creationState
|
||||
);
|
||||
final NavigablePath fetchablePath = fetchParent.getNavigablePath().append( fetchable.getFetchableName() );
|
||||
|
||||
if ( biDirectionalFetch != null ) {
|
||||
fetches.add( biDirectionalFetch );
|
||||
final Fetch biDirectionalFetch = fetchable.resolveCircularFetch(
|
||||
fetchablePath,
|
||||
fetchParent,
|
||||
creationState
|
||||
);
|
||||
|
||||
if ( biDirectionalFetch != null ) {
|
||||
fetches.add( biDirectionalFetch );
|
||||
return;
|
||||
}
|
||||
|
||||
LockMode lockMode = LockMode.READ;
|
||||
FetchTiming fetchTiming = fetchable.getMappedFetchStrategy().getTiming();
|
||||
boolean joined = fetchable.getMappedFetchStrategy().getStyle() == FetchStyle.JOIN;
|
||||
|
||||
final Integer maximumFetchDepth = creationContext.getMaximumFetchDepth();
|
||||
|
||||
if ( maximumFetchDepth != null ) {
|
||||
if ( fetchDepth == maximumFetchDepth ) {
|
||||
joined = false;
|
||||
}
|
||||
else if ( fetchDepth > maximumFetchDepth ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LockMode lockMode = LockMode.READ;
|
||||
FetchTiming fetchTiming = fetchable.getMappedFetchStrategy().getTiming();
|
||||
boolean joined = fetchable.getMappedFetchStrategy().getStyle() == FetchStyle.JOIN;
|
||||
|
||||
// if ( loadable instanceof PluralValuedNavigable ) {
|
||||
// // processing a collection-loader
|
||||
//
|
||||
// // if the `fetchable` is the "collection owner" and the collection owner is available in Session - don't join
|
||||
// final String collectionMappedByProperty = ( (PluralValuedNavigable) rootContainer ).getCollectionDescriptor()
|
||||
// .getMappedByProperty();
|
||||
// if ( collectionMappedByProperty != null && collectionMappedByProperty.equals( fetchable.getNavigableName() ) ) {
|
||||
// joined = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
final Integer maximumFetchDepth = creationContext.getMaximumFetchDepth();
|
||||
|
||||
if ( maximumFetchDepth != null ) {
|
||||
if ( fetchDepth == maximumFetchDepth ) {
|
||||
joined = false;
|
||||
}
|
||||
else if ( fetchDepth > maximumFetchDepth ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if ( !( fetchable instanceof BasicValuedModelPart ) ) {
|
||||
fetchDepth++;
|
||||
}
|
||||
Fetch fetch = fetchable.generateFetch(
|
||||
fetchParent,
|
||||
fetchablePath,
|
||||
fetchTiming,
|
||||
joined,
|
||||
lockMode,
|
||||
null,
|
||||
creationState
|
||||
);
|
||||
fetches.add( fetch );
|
||||
|
||||
try {
|
||||
if ( ! (fetchable instanceof BasicValuedModelPart ) ) {
|
||||
fetchDepth++;
|
||||
}
|
||||
Fetch fetch = fetchable.generateFetch(
|
||||
fetchParent,
|
||||
if ( fetchable instanceof PluralAttributeMapping && fetchTiming == FetchTiming.IMMEDIATE ) {
|
||||
applyOrdering(
|
||||
querySpec,
|
||||
fetchablePath,
|
||||
fetchTiming,
|
||||
joined,
|
||||
lockMode,
|
||||
null,
|
||||
( (PluralAttributeMapping) fetchable ),
|
||||
creationState
|
||||
);
|
||||
fetches.add( fetch );
|
||||
|
||||
if ( fetchable instanceof PluralAttributeMapping && fetchTiming == FetchTiming.IMMEDIATE ) {
|
||||
applyOrdering(
|
||||
querySpec,
|
||||
fetchablePath,
|
||||
( (PluralAttributeMapping) fetchable ),
|
||||
creationState
|
||||
);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ( ! (fetchable instanceof BasicValuedModelPart) ) {
|
||||
fetchDepth--;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ( !( fetchable instanceof BasicValuedModelPart ) ) {
|
||||
fetchDepth--;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void applyOrdering(
|
||||
|
|
Loading…
Reference in New Issue