Reputation: 266
I'm trying to achieve pagination with cassandra but I'm not getting any successful solutions on Stackoverflow. The prominent error I'm getting is 'Paging queries for pages other than the first one require a CassandraPageRequest with a valid paging state'. Kindly assist.
Upvotes: 2
Views: 2962
Reputation: 2938
You must use the CassandraPageRequest.of(pageIndex, resultsOnPage)
Also to be able to use findAll query with page you must extends your repository interface with CassandraRepositoy
to have the implementation for the query.
Example :
@Repository
public interface MyRepository extends CassandraRepository<MyModel, MapId>{
}
@Autowired
private MyRepo repo;
void someMethod(){
int resultOnPage = ...
//this is the first page
Slice<MyModel> page= repository.findAll(CassandraPageRequest.of(0, resultOnPage ));
// iterate the slice with iterator
//.......
//go ahead and take the next pages
while (page.hasNext()) {
page = repository.findAll(page.nextPageable());
//process the page iterating it
}
}
Upvotes: 4