diff --git a/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java b/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java index 4140c607e..bce3000e8 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java +++ b/src/main/java/com/avaje/ebeaninternal/server/querydefn/OrmQueryDetail.java @@ -172,17 +172,13 @@ public class OrmQueryDetail implements Serializable { Collections.sort(matchingPaths); // the list of secondary queries - ArrayList props = new ArrayList(2); + ArrayList props = new ArrayList(); for (int i = 0; i < matchingPaths.size(); i++) { String path = matchingPaths.get(i); includes.remove(path); OrmQueryProperties secQuery = fetchPaths.remove(path); - if (secQuery == null) { - // the path has already been removed by another - // secondary query - - } else { + if (secQuery != null) { props.add(secQuery); // remove any child properties for this path @@ -332,8 +328,7 @@ public class OrmQueryDetail implements Serializable { // this is a join to a *ToMany OrmQueryProperties chunk = fetchPaths.get(fetchPath); - if (chunk.isFetchJoin() && !isLazyLoadManyRoot(lazyLoadManyPath, chunk) - && !hasParentSecJoin(lazyLoadManyPath, chunk)) { + if (isQueryJoinCandidate(lazyLoadManyPath, chunk)) { // this is a 'fetch join' (included in main query) if (fetchJoinFirstMany) { // letting the first one remain a 'fetch join' @@ -353,6 +348,15 @@ public class OrmQueryDetail implements Serializable { } } + /** + * Return true if this path is a candidate for converting to a query join. + */ + private boolean isQueryJoinCandidate(String lazyLoadManyPath, OrmQueryProperties chunk) { + return chunk.isFetchJoin() + && !isLazyLoadManyRoot(lazyLoadManyPath, chunk) + && !hasParentSecJoin(lazyLoadManyPath, chunk); + } + /** * Return true if this is actually the root level of a +query/+lazy loading query. */