Spring Boot Couchbase Reactive isn't supporting Pagination

438 views Asked by At

I'm trying to implement Pagination in my Reactive WebFlux app and my DB is Couchbase.

The Spring Data Couchbase doc allows me to pass Pageable as an argument in my Repository.

Flux<Person> findByFirstnameOrderByLastname(String firstname, Pageable pageable);

However, when I try to implement it I get the below error:

Caused by: java.lang.IllegalStateException: Method has to have one of the following return types! [interface org.springframework.data.domain.Slice, interface java.util.List, interface org.springframework.data.domain.Page]

My Repository method looks like this:

Flux<Building> findAll(Pageable pageable);

However, if I use this workaround, I've no problem.

@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} LIMIT $1 OFFSET $2")
Flux<Building> findAll(Integer limit, Integer offset);

Is this a bug? Or, am I using it wrong?

Spring Boot version: 2.2.7.RELEASE

Full Repository:

@Repository
public interface BuildingRepository extends ReactiveSortingRepository<Building, String> {

    @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} LIMIT $1 OFFSET $2")
    Flux<Building> findAll(Integer limit, Integer offset);

    //This works if I comment the below
    Flux<Building> findAll(Pageable pageable);
}
1

There are 1 answers

0
mn_test347 On

The short answer is that the documentation is not current, and the best solution is to implement paging yourself with limit and offset as you have done. There is work underway to remedy this in https://jira.spring.io/browse/DATACOUCH-588 (it's not described there, but that's the tracking issue)

Even so, a more efficient way of paging is key-set pagination ( https://use-the-index-luke.com/no-offset ) - but you’ll need to implement that in your application. It uses the indexes to get the items beginning with the first one required, instead of “skipping” over the ones in prior pages.