spring cassandra数据版本2.1.4分页
spring cassandra data Version 2.1.4 pagination
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:
Type definition error: [simple type, class
com.datastax.driver.core.PagingState]; nested exception is
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No
serializer found for class com.datastax.driver.core.PagingState and no
properties discovered to create BeanSerializer (to avoid exception,
disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference
chain:
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[=18=](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.FluxDefaultIfEmpty$DefaultIfEmptySubscriber.onNext(FluxDefaultIfEmpty.java:92)","reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1476)","reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:241)","reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:121)","reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.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.FluxIterable$IterableSubscription.request(FluxIterable.java:198)"],
2。与 ReactiveSortingRepository 反应
回购:
public interface LocationRepository extends ReactiveSortingRepository<MyClass, String> {
}
通话:
repository.findAll(CassandraPageRequest.first(20))
错误:
Syntax error: findAll can't be applied to CassandraPageRequest.
3。简单调用获取页面。
回购:
public interface MyRepository extends CassandraRepository<MyClass, MyClassKey> {
Page<MyClass> findByKeyTerminalIdAndSolrQuery(String solrQuery, Pageable page);
}
启动时出错:
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException:
Page queries are not supported. Use a Slice query.
4。使用 PagingAndSortingRepository
回购:
public interface MyRepository extends PagingAndSortingRepository<MyClass, MyClassKey> {
}
通话:
Page<Vessel> vessels = repository.findAll(CassandraPageRequest.first(10));
错误:
springframework.data.mapping.PropertyReferenceException: No property
findAll found for type MyClass!
欢迎来到 Stack Overflow。
第一个例子是合适的:
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));
问题是当您将 SliceImpl
(Slice
的实现)传递给 WebFlux 时,Jackson 无法对其进行编码(根据堆栈跟踪)。所以查询产生了正确的结果,但是如果你想 JSON 编码它,你需要传递 Slice
内容,而不是 Slice
本身。
相关说明:ReactiveCassandraRepository
未实现 ReactiveSortingRepository
,因为带有 Sort
参数的 Casandra 查询始终需要 WHERE
子句。查看 ReactiveSortingRepository
,您会看到一个 findAll(Sort)
方法不采用过滤条件:
public interface ReactiveSortingRepository<T, ID> extends ReactiveCrudRepository<T, ID> {
Flux<T> findAll(Sort sort);
}
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: Type definition error: [simple type, class com.datastax.driver.core.PagingState]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.datastax.driver.core.PagingState and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: 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[=18=](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.FluxDefaultIfEmpty$DefaultIfEmptySubscriber.onNext(FluxDefaultIfEmpty.java:92)","reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1476)","reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:241)","reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:121)","reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.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.FluxIterable$IterableSubscription.request(FluxIterable.java:198)"],
2。与 ReactiveSortingRepository 反应
回购:
public interface LocationRepository extends ReactiveSortingRepository<MyClass, String> {
}
通话:
repository.findAll(CassandraPageRequest.first(20))
错误:
Syntax error: findAll can't be applied to CassandraPageRequest.
3。简单调用获取页面。
回购:
public interface MyRepository extends CassandraRepository<MyClass, MyClassKey> {
Page<MyClass> findByKeyTerminalIdAndSolrQuery(String solrQuery, Pageable page);
}
启动时出错:
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Page queries are not supported. Use a Slice query.
4。使用 PagingAndSortingRepository
回购:
public interface MyRepository extends PagingAndSortingRepository<MyClass, MyClassKey> {
}
通话:
Page<Vessel> vessels = repository.findAll(CassandraPageRequest.first(10));
错误:
springframework.data.mapping.PropertyReferenceException: No property findAll found for type MyClass!
欢迎来到 Stack Overflow。
第一个例子是合适的:
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));
问题是当您将 SliceImpl
(Slice
的实现)传递给 WebFlux 时,Jackson 无法对其进行编码(根据堆栈跟踪)。所以查询产生了正确的结果,但是如果你想 JSON 编码它,你需要传递 Slice
内容,而不是 Slice
本身。
相关说明:ReactiveCassandraRepository
未实现 ReactiveSortingRepository
,因为带有 Sort
参数的 Casandra 查询始终需要 WHERE
子句。查看 ReactiveSortingRepository
,您会看到一个 findAll(Sort)
方法不采用过滤条件:
public interface ReactiveSortingRepository<T, ID> extends ReactiveCrudRepository<T, ID> {
Flux<T> findAll(Sort sort);
}