-
Notifications
You must be signed in to change notification settings - Fork 54
One-to-many queries join the same tables twice #216
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
I know about this. The query builder actually creates a single join fetch, but Hibernate adds another fetch for many to many associations. It does not happen for one to many associations. I will investigate it further to double check. |
Thanks. I'm investigating adding hooks to allow user-defined entity-specific predicates to be added when an entity is added to the query. In the example above it seems that Line 233 in 5d99c3b
character2_ but the data in the GraphQL response is coming from character4_.name3_7_2_ where character4_ seems to be the mysteriously-generated join that I can't see where to add predicates to.
|
@molexx This is the JPQL query generated before execution at Line 139 in 0151eec
There is no extra fetch join generated by the library. The Hibernate adds this extra join for some reason only if it is a many-to-many association. I remember I have spent considerable amount of time trying to debug Hibernate code to understand the logic behind this, but I was not successful since I ran out of time. It looks like a feature in Hibernate. There is more, the Hibernate also executes two more queries for What are you trying to do with custom predicates? It should be easy to add support for a hook registry to be able to mutate query search criterias by adding custom predicates. |
Thanks very much, will take a look! Custom predicates is a generic solution to restricting rows that are returned using server-side rules, defined per-entity. My immediate use-case is by relation to the currently logged in user but let's design a generic system for others. I'm working on a PR for this with a bunch of tests, I should be able to continue with the one-to-many ones now. I'm adding a call to a few places in |
RE the Hibernate CodeList queries ignoring the Lazy, I wonder if that is similar to #114 , which I think is because of this Hibernate bug: https://hibernate.atlassian.net/browse/HHH-8776 |
There is not much can be done about it at the moment. I have observed that CodeList hierarchy get loaded when the entity manager is cold, i.e. during the first query. After that, there are no extra queries generated for the second query, so it looks like it is cached by Hibernate. |
Would you be able to start a new issue that describes the use case in detail? I have some ideas how to make it pluggable with annotation processing that use SpEL similar to https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions |
The
StarwarsQueryExecutorTests.queryOneToManyJoinByID
test looks like this:and executes the following SQL:
It seems that the joins to
friends3_
andcharacter4_
duplicate the joins tofriends1_
andcharacter2_
and are unnecessary?This is tested using commit 0151eec from master which includes the fix for #198 .
Removing the
where id=1000
clause makes no difference.The text was updated successfully, but these errors were encountered: