Couchbase&春季查询错误:“返回原始类型的查询应返回精确的1个结果,得到X". [英] Couchbase & Spring query error: "Query returning a primitive type are expected to return exactly 1 result, got X"

查看:60
本文介绍了Couchbase&春季查询错误:“返回原始类型的查询应返回精确的1个结果,得到X".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In our spring-boot 2.0.4.RELEASE application, we are using Couchbase version 5.5.1 build 3511 with Spring.

我们向存储库界面添加了一个新的删除方法:

We added a new delete method to the Repository interface:

public interface CatRepository extends CouchbaseRepository<Cat, String> {

  long deleteAllByName(String name);

调用该方法时,文档将从存储桶中删除,但出现以下错误:

When calling the method, documents are deleted from the bucket, but we get the following error:

返回原始类型的查询应返回精确的1个结果,得到X

Query returning a primitive type are expected to return exactly 1 result, got X

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

The X value is changed according to the number of items that were deleted. In the example below, 27 items were deleted.

这是完整的堆栈跟踪:

    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]
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[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]
    at org.springframework.data.couchbase.repository.support.ViewPostProcessor$ViewInterceptor.invoke(ViewPostProcessor.java:87) ~[spring-data-couchbase-3.0.9.RELEASE.jar:3.0.9.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[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]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at com.sun.proxy.$Proxy130.deleteAllByName(Unknown Source)

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

We also tried to change the return type of the deleteAllByName(String name); to be void, but it has the same results.

在pom中,这些是客户端版本:

In the pom, these are the client versions:

        <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-couchbase</artifactId>
        <version>3.0.9.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>

    <dependency>
        <groupId>com.couchbase.client</groupId>
        <artifactId>couchbase-client</artifactId>
        <version>1.4.13</version>
    </dependency>

推荐答案

据我所知,您必须返回要删除的对象:

As far as I know, you must return the object that you are removing:

@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "maintenanceSchedule")
public interface MaintenanceScheduleRepository extends CouchbasePagingAndSortingRepository<MaintenanceSchedule, String> {

    List<MaintenanceSchedule> deleteByCompanyIdAndMaintenancePlanId(String companyId, String maintenancePlanId);

    List<MaintenanceSchedule> deleteByCompanyIdAndResourceIdAndMaintenancePlanIdIn(String companyId, String resourceId,
                                                                               List<String> maintenancePlanIds);

}

如果不需要删除的对象,最好的方法是直接执行N1QL查询.

If you don't need the removed objects, the best approach is to execute a N1QL query directly.

这篇关于Couchbase&amp;春季查询错误:“返回原始类型的查询应返回精确的1个结果,得到X".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆