Skip to content
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

Pagination does not work with eager join fetch of association [DATAJPA-35] #473

Closed
spring-projects-issues opened this issue Mar 1, 2011 · 10 comments
Assignees
Labels
in: core Issues in core support type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Mar 1, 2011

Stevo Slavić opened DATAJPA-35 and commented

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

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 1, 2011

Oliver Drotbohm commented

Hi,

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?

Cheers,
Ollie

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 1, 2011

Oliver Drotbohm commented

Here's the link to the discussion:

http://redmine.synyx.org/issues/361

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 1, 2011

Stevo Slavić commented

Yes, that's it, after defining additional countQuery="SELECT count(u) FROM User u" it works. It's not a bug. Couldn't close issue myself. Appologies for making noise

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 1, 2011

Oliver Drotbohm commented

No problem, thanks for your feedback ;)

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 13, 2012

Piotr Jagielski commented

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.

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 13, 2012

Piotr Jagielski commented

On second thought it could probably remove the fetch part altogether instead of just the keyword because fetching shouldn't affect the number of results.

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Oct 10, 2012

Manish Shukla commented

I am using Specifications to form Predicates dynamically. Using countQuery is not possible, is there any other workaround to this issue for Specification ?

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 13, 2012

P. J. Reed commented

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

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 17, 2012

Oliver Drotbohm commented

Please open a dedicated ticket. This one here is not involving specifications at all

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 17, 2012

P. J. Reed commented

Done; see DATAJPA-278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants