question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repository returns PageImpl and executes count query when using Slice as return type [DATAJPA-1464]

See original GitHub issue

Martin 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:open
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
odrotbohmcommented, Jun 20, 2022

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! 🙃

1reaction
odrotbohmcommented, Jun 20, 2022

You actually are, as in fact the JPA implementation of CrudRepository, SimpleJpaRepository implements PagingAndSortingRepository in preparation of our users declaring PASR 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found