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



我的Spring boot应用程序正在尝试从Couchbase存储桶中获取所有类型为Cat的文档。

有一个索引:

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

还有一个Repository类:

public interface CatRepository extends CouchbaseRepository<Cat, String>

从代码调用此内容时

Iterable<Cat> all = catRepository.findAll();

我得到这个异常:

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 的当前实现仍然在内部使用视图来实现 findAll 和 removeAll 等方法(在 SDK 版本 3.0 上不再使用视图(。因此,您可以为此文档类型创建一个视图,也可以自己实现一个新的 findAll 方法:

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

该方法应使用您的cats_idx

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

在使用沙发底座时,我遇到了同样的问题,并且是否有 .findAll(( 方法正在执行。所以我在存储库类中给出了以下注释。

@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "product",viewName = "all")
public interface ProductRepository extends CouchbaseRepository<Product,Integer> {
}

上述方法对我有用。

最新更新