gpt4 book ai didi

java - Spring JPA & Couchbase - com.couchbase.client.java.error.ViewDoesNotExistException : View cat/all does not exist

转载 作者:行者123 更新时间:2023-12-04 10:49:15 25 4
gpt4 key购买 nike

我的 Spring boot应用程序正在尝试获取 Cat 类型的所有文档来自 Couchbase桶。

有一个索引:

CREATE INDEX cats_idx ON `cats`(_class) WHERE _class = 'com.example.Cat'

还有一个 Repository类(class):
public interface CatRepository extends CouchbaseRepository<Cat, String>

从代码中调用它时
Iterable<Cat> all = catRepository.findAll();

我得到这个异常(exception):
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request 
processing failed; nested exception is
org.springframework.dao.InvalidDataAccessResourceUsageException: View cat/all does not exist.;
nested exception is com.couchbase.client.java.error.ViewDoesNotExistException: View cat/all does not
exist.] with root cause
rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.java.document.json.JsonObject.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:118)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:73)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
at rx.internal.producers.SingleProducer.request(SingleProducer.java:65)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at rx.internal.operators.OperatorSingle$ParentSubscriber.onCompleted(OperatorSingle.java:113)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:281)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:216)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

最佳答案

Spring Data SDK 的当前实现仍然在内部使用 View 用于 findAll 和 removeAll 等方法(SDK 3.0 版不再使用 View )。因此,您可以为此文档类型创建一个 View ,也可以自己实现一个新的 findAll 方法:

@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} ")
List<Cat> all();

该方法应该使用您的cats_idx

PS:cats_idx 不是最优的,你不应该在索引中存储 _class 属性。

关于java - Spring JPA & Couchbase - com.couchbase.client.java.error.ViewDoesNotExistException : View cat/all does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59565633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com