Repository returns PageImpl and executes count query when using Slice as return type [DATAJPA-1464]
See original GitHub issueMartin Möller opened DATAJPA-1464 and commented
public interface JavaUserRepositoryWithImplicitQuery extends Repository<User, Long> {
Slice<User> findAll(Pageable pageable);
}
This repository returns at runtime a PageImpl and a count query is run against the db. As far as I understand Slice and Page, this should not happen.
The linked reproducer (branch is called slice) has tests that check for SliceImpl. Relevant is only the count query and not the implementation of Slice but they seem to be related. Logging is activated where the count query can be observed
Affects: 2.1.2 (Lovelace SR2)
Reference URL: https://bitbucket.org/martinmo/spring-data-jpa-demo/src/4e2605ebfbaad16d973b6dbdc14b6d066b3a7fec/?at=slice
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Repository returns PageImpl and executes count ... - GitHub
Simplifies the development of creating a JPA-based data access layer. - Repository returns PageImpl and executes count query when using Slice as return...
Read more >Spring Data PageImpl not returning page with the correct size?
The problem for me is I want to use Java 8's lambda to query the database via Spring Data JPA. Im used to...
Read more >Spring Data JPA - Pagination using Pageable parameter and ...
Spring supports Slice as a return type of the query method. Pageable parameter must be specified by the same query method.
Read more >Patterns for Iterating Over Large Result Sets With Spring Data ...
With Spring Data JPA, we simply need to add to the JpaRepository a method that receives a Pageable as a parameter and returns...
Read more >Pagination with Spring Data JPA
A comprehensive guide on learning how to use paginate query ... To avoid this costly count query, you should instead return a Slice...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That said, I can see why this is not immediately obvious that a call to the method would be executed that way. However, changing that would cause significant rework to the internal routing of calls, and I am not quite sure that I currently oversee the side effects of not routing the method call through the actual implementation but essentially executing a derived query for it. I’ll take this to the team for discussion.
Thanks for digging this up, though! 🙃
You actually are, as in fact the JPA implementation of
CrudRepository
,SimpleJpaRepository
implementsPagingAndSortingRepository
in preparation of our users declaringPASR
as repository super type.Page<T> findAll(Pageable)
is not a query method, and thus the optimization by using the different query method return type does not work. That’s what I am trying to say.