-
Notifications
You must be signed in to change notification settings - Fork 1.5k
count query fails to be auto generated when using @Query annotation with fetch join #2348
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
A temporary workaround is to provide the specific count query.
|
We are working on a parsing solution to better handle such situations than |
With the new parser in place we can opt for
or
Are you saying that Hibernate wants count queries to DROP the |
SELECT count(DISTINCT b) FROM Board b LEFT JOIN b.comments Yes, Hibernate wants count queries to DROP the FETCH aspect of JOINs for count operations |
Any recommended workaround to solve it on JpaSpecificationExecutor.html#findAll(Specification spec, Pageable pageable) at Spring Data JPA 2? |
For anyone in the same situation, one fragile alternative without using AOP is to override the class Be aware that you'd have to update it whenever Hibernate is upgraded on your project to avoid incompatibility issues. |
findAllFetch method causes the following error. however, findAllNotFetch method does not cause errors.
because the automatically generated countQuery does not include the fetch keyword. likewise, fetch join paging using @entitygraph does not cause an error.
whether it is fetch join or not does not affect count query results. what is important is the association of the fetching entity.
of course, I know that the count query generated in the findAllNotFetch method has inaccurate paging. but, paging would have been accurate if it was not a collection fetch.
i wonder, the QueryUtils class removes unnecessary queries that do not affect results such as order by, but why the fetch does not. Is this intentional?
The text was updated successfully, but these errors were encountered: