Skip to content

Consider to incorporate Slice returning method into JpaSpecificationExecutor #4067

@mipo256

Description

@mipo256

When it comes to pagination, we may either use Page or Slice. The Slice allows for trivial pagination where we do not really need to know the total amount of records in the database that potentially satisfy our criteria, so there is no need for the subsequent COUNT query.

The Slice itself is very useful, but unfortunately currently it is not that easy to use with Specifications. The JpaSpecificationExecutor defines methods like:

    List<T> findAll(@Nullable Specification<T> spec);

    Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable);

    List<T> findAll(@Nullable Specification<T> spec, Sort sort);

But sometimes just Slice would suffice. There are some solutions that people came up with, please, see this StackOverFlow thread and the corresponding solution (extension of SimpleJpaRepository, providing a custom RepositoryFactoryBean and etc.).

I want to kindly ask to consider the introduction of method like:

Slice<T> findAll(@Nullable Specification<T> spec, Pageable pageable);

So this method both accepts the Pageable, but it returns the Slice, not the Page.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions