-
Notifications
You must be signed in to change notification settings - Fork 54
Join Fetch applied twice for ElementCollection #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@vokinpirks Thank you for reporting this problem. :) There should be only one fetch join generated for element collections here: Line 233 in 9854252
The first join is needed to fetch the data from the graphql query. The inner join should not be there unless you want to filter elements in your collection. It is probably a side effect from the predicate builder somewhere. I will try to create a test to find out and fix it. The batch fetching is not part of JPA spec, so it cannot be used directly. I am also not sure what effect Graphql-java has something called DataLoader: https://github.com/graphql-java/java-dataloader. I have not figured out how to use it, but may be your case is a good candidate to do it. |
@igdianov the first join is left whereas the second one is inner. Line 224 in 9854252
The line of code you are referring to always produces inner join despite the fact isOptional set to true. The method javax.persistence.criteria.FetchParent#fetch(java.lang.String) has an overloaded signature which takes JoinType as a parameter. Thanks for pointing me to DataLoader. Will take a look at that. |
@vokinpirks Yes, this is a bug. It should not be apply to fetch joins for element collections. It will be easy to fix. |
…elements (#200) * fix: adedd support for fetching optional element collections elements * fix(test): polished queryOptionalElementCollections * polish(test): added tags selection field to queryOptionalElementCollections
@vokinpirks I have fixed the issue. Let me know if it works for you. |
@igdianov thanks! I'll try this out. |
Hi!
I'm playing around with this library and encountered an issue.
I have pretty simple JPA model. There is element collection defined as follows:
When I do NOT include this field in query everything works fine:
But when I do so, I get an empty result:
'tags' field is empty for all entities.
I checked generated JPQL/SQL queries and found out that there are two joins for tags, left and inner one. I guess I'm getting the empty result because of that inner join.
I started debugging and figured out that the second join is added at
com.introproventures.graphql.jpa.query.schema.impl.QraphQLJpaBaseDataFetcher.java:234
(root.fetches becomes [2] there).
And..join is a very inefficient way of fetching *ToMany/ElemectCollection relations. Batch fetching is a way better for that. Theoretically, is it possible to implement batch fetching in this library?
The text was updated successfully, but these errors were encountered: