spring cassandra数据版本2.1.4分页

ycggw6v2  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(509)

根据文件:https://docs.spring.io/spring-data/cassandra/docs/2.1.4.release/reference/html/#repositories.limit-查询结果
spring cassandra数据使得获得分页信息变得很容易。但我不能让它工作。
回购、赎回和错误:
1被动呼叫
回购:

public interface MyRepository extends ReactiveCassandraRepository<MyClass, String> {
  @Query("select * from my_keyspace.my_table where solr_query = ?0")
  Mono<Slice<MyClass>> findMono(String solrQuery, Pageable page);
}

电话:

Mono<Slice<MyClass>>  repository.findMono(queryString, CassandraPageRequest.first(20));

错误:
“exceptiondescription”:“org.springframework.core.codec.codecexception:类型定义错误:[simple type,class com.datastax.driver.core.pagingstate];嵌套异常为com.fasterxml.jackson.databind.exc.invaliddefinitionexception:找不到类com.datastax.driver.core.pagingstate的序列化程序,也找不到创建beanserializer的属性(为了避免异常,禁用serializationfeature.fail\u on \u empty\u bean)(通过引用链:org.springframework.data.domain.sliceimpl[\“pageable\”]->org.springframework.data.cassandra.core.query.cassandrapagerequest[\“pagingstate\”],“lines”:[“org.springframework.http.codec.json.abstractjackson2encoder.encodevalue(abstractjackson2encoder)。java:175)",org.springframework.http.codec.json.abstractjackson2encoder.lambda$encode$0(abstractjackson2encoder)。java:122)“,”reactor.core.publisher.fluxmap$mapsubscriber.onnext(fluxmap。java:100)“,”reactor.core.publisher.fluxswitchifempty$switchifemptysubscriber.onnext(fluxswitchifempty)。java:67)",“reactor.core.publisher.fluxmap$mapsubscriber.onnext(fluxmap。java:114)“,”reactor.core.publisher.fluxDefaultyFempty$defaultifemptysubscriber.onnext(fluxDefaultyFempty。java:92)“,”reactor.core.publisher.operators$monosubscriber.complete(运算符。java:1476)“,”reactor.core.publisher.monoflatmap$flatmainer.onnext(monoflatmap。java:241)",reactor.core.publisher.fluxmapfusable$mapfuseablesubscriber.onnext(fluxmapfusable。java:121)“,”reactor.core.publisher.operators$monosubscriber.complete(运算符。java:1476)“,”reactor.core.publisher.monocollectlist$monobufferallsubscriber.oncomplete(monocollectlist。java:118)",“reactor.core.publisher.fluxtake$takefuseablesubscriber.oncomplete(fluxtake。java:424)“,”reactor.core.publisher.fluxtake$takefuseablesubscriber.onnext(fluxtake。java:404)“,”reactor.core.publisher.fluxiterable$iterablesubscription.fastpath(fluxiterable。java:311)",“reactor.core.publisher.fluxitable$iterablesubscription.request(fluxitable。java:198)"],
2与reactivesortingrepositoryReact
回购:

public interface LocationRepository extends ReactiveSortingRepository<MyClass, String> {
}

电话:

repository.findAll(CassandraPageRequest.first(20))

错误:
语法错误:findall不能应用于cassandrapagerequest。
三。简单的调用获取页面。
回购:

public interface MyRepository extends CassandraRepository<MyClass, MyClassKey> {
Page<MyClass> findByKeyTerminalIdAndSolrQuery(String solrQuery, Pageable page);
}

启动时出错:
原因:org.springframework.dao.invaliddataaccessapiusageexception:不支持页面查询。使用切片查询。
4使用分页和排序存储库
回购:

public interface MyRepository extends PagingAndSortingRepository<MyClass, MyClassKey> {

}

电话:

Page<Vessel> vessels = repository.findAll(CassandraPageRequest.first(10));

错误:
springframework.data.mapping.propertyreferenceexception:找不到myclass类型的属性findall!

3qpi33ja

3qpi33ja1#

欢迎使用堆栈溢出。
第一个例子是适当的:

public interface MyRepository extends ReactiveCassandraRepository<MyClass, String> {
  @Query("select * from my_keyspace.my_table where solr_query = ?0")
  Mono<Slice<MyClass>> findMono(String solrQuery, Pageable page);
}

Mono<Slice<MyClass>>  repository.findMono(queryString, CassandraPageRequest.first(20));

问题是Jackson不能编码一个 SliceImpl (b)执行 Slice )当您将其传递给webflux时(根据堆栈跟踪)。所以查询会产生正确的结果,但是您需要传递 Slice 内容,而不是 Slice 如果你想用json编码的话。
另请注意: ReactiveCassandraRepository 不执行 ReactiveSortingRepository 因为Cassandra用一个 Sort 争论总是需要一个 WHERE 条款。看着 ReactiveSortingRepository ,你会看到 findAll(Sort) 不采用筛选条件的方法:

public interface ReactiveSortingRepository<T, ID> extends ReactiveCrudRepository<T, ID> {
    Flux<T> findAll(Sort sort);
}

相关问题