Couchbase & Spring 查询错误:“返回原始类型的查询预计将返回 1 个结果

在我们的spring-boot 2.0.4.RELEASE应用程序中,我们使用Couchbase version 5.5.1 build 3511with Spring。


我们在 Repository 接口中添加了一个新的删除方法:


public interface CatRepository extends CouchbaseRepository<Cat, String> {


  long deleteAllByName(String name);

调用该方法时,文档从存储桶中删除,但我们收到以下错误:


返回原始类型的查询预计将返回 1 个结果,得到 X


该X 值根据删除的项目数而变化。在下面的示例中,删除了 27 个项目。


这是完整的堆栈跟踪:


    Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Query returning a primitive type are expected to return exactly 1 result, got 27] with root cause


org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Query returning a primitive type are expected to return exactly 1 result, got 27

    at org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.executeSingleProjection(AbstractN1qlBasedQuery.java:203) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]

    at org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.executeDependingOnType(AbstractN1qlBasedQuery.java:143) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]

    at org.springframework.data.couchbase.repository.query.AbstractN1qlBasedQuery.execute(AbstractN1qlBasedQuery.java:106) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]

    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:590) ~[spring-data-commons-2.0.9.RELEASE.jar:2.0.9.RELEASE]

    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578) ~[spring-data-commons-2.0.9.RELEASE.jar:2.0.9.RELEASE]

    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]


我们还尝试将 的返回类型更改deleteAllByName(String name);为void,但结果相同。


蝴蝶不菲
浏览 101回答 1
1回答

MM们

据我所知,您必须返回要删除的对象:@N1qlPrimaryIndexed@ViewIndexed(designDoc = "maintenanceSchedule")public interface MaintenanceScheduleRepository extends CouchbasePagingAndSortingRepository<MaintenanceSchedule, String> {&nbsp; &nbsp; List<MaintenanceSchedule> deleteByCompanyIdAndMaintenancePlanId(String companyId, String maintenancePlanId);&nbsp; &nbsp; List<MaintenanceSchedule> deleteByCompanyIdAndResourceIdAndMaintenancePlanIdIn(String companyId, String resourceId,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List<String> maintenancePlanIds);}如果不需要删除的对象,最好的方法是直接执行 N1QL 查询。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java