Query like "SELECT u FROM User u JOIN FETCH u.roles r" doesn't work if repository/DAO method returns org.springframework.data.domain.Page - library tries to calculate total count with additional query "select count(u) FROM foo.bar.User u JOIN FETCH u.roles r" which throws "org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list"
Affects: 1.0 M1
4 votes, 5 watchers
The text was updated successfully, but these errors were encountered:
we had discussed that in Hades already. There's a countQuery attribute at the @Query annotation that allows you to define the query to be used for counting. I don't really want to go down the route of String manipulation for removing parts of the query. So does that workaround do the trick for you?
Using countQuery is a valid workaround but I think it should better be handled by the framework. Having to repeat almost the same query twice is cumbersome, especially when the query is large. It may also result in hard to spot bugs when the main query changes and one forgets to update the count query. The referenced discussion mentions a better solution to remove fetch keywords from the count query.
I just run into this issue; I'm using .findAll on a repository and passing in a Specification, and it's fairly frustrating that I am apparently unable to specify fetches because it breaks the count query