Skip to content

Add the possibility to fetch using Specification and Pageable but without doing a count query #2762

Closed as duplicate
@Artur-

Description

@Artur-

If you use Page<T> findAll(Pageable pageable) then Spring Data will execute the select plus the count query for every call. To get rid of the count query when you do not need the total count, you can add a find by without any filters: List<T> findBy(Pageable pageable). You cannot add a List<T> findAll(Pageable pageable) as it will conflict with findAll that returns a Page<T>.

However when you use a Specification for filtering you still would want the same possibility: to get rid of the count query.
The available findAll is Page<T> findAll(Specification<T> spec, Pageable pageable) which again prevents adding a List<T> findAll(Specification<T> spec, Pageable pageable). Also it seems that the findBy "hack" cannot be used as a method like List<T> findBy(Specification<T> filter, Pageable pageable); will throw

org.springframework.dao.InvalidDataAccessApiUsageException: At least 1 parameter(s) provided but only 0 parameter(s) present in query

Is there another way to accomplish this or could it be added as a feature?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions