Spring 带有@Query 和 Pageable / Sort 抛出 ArrayIndexOutOfBoundsException 的数据 Couchbase - PagingAndSortingRepository、CouchbaseRepository
Spring Data Couchbase with @Query and Pageable / Sort throwing ArrayIndexOutOfBoundsException - PagingAndSortingRepository, CouchbaseRepository
我正在尝试使用连接到 couchbase 的 @Query 注释执行自定义查询,我期待寻呼响应。
我有如下代码
控制器
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@GetMapping("/getEmployees/{page}/{size}")
public Page<Employee> getEmployees(@PathVariable int page, @PathVariable int size) {
Pageable pageable = PageRequest.of(page, size);
return employeeRepositoryTwo.findEmployeeDetails(pageable);
}
存储库
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.couchbase.repository.Query;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface EmployeeRepositoryTwo extends CouchbaseRepository<Employee, Integer> {
Employee findByEmpName(String empName);
Page<Employee> findByEmpName(String empName, Pageable pageable);
@Query("#{#n1ql.selectEntity} WHERE empName='Ravi'")
Page<Employee> findEmployeeDetails(Pageable pageable);
}
接电话
"http://localhost:8080/getEmployees/1/2"
我得到
java.lang.ArrayIndexOutOfBoundsException: 0
org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider.lambda$collectVariables[=14=](ExtensionAwareQueryMethodEvaluationContextProvider.java:116)
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)\r\n\tat java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:175)\r\n\tat java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:899)
.
.
而且我能够得到这个方法调用的响应
Page<Employee> findByEmpName(String empName, Pageable pageable);
所以当我使用如下所示的可分页注释的@Query 时,问题就来了
@Query("#{#n1ql.selectEntity} WHERE empName='Ravi'")
Page<Employee> findEmployeeDetails(Pageable pageable);
我的依赖树
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ couchbase ---
[INFO] com.ravi:couchbase:jar:0.0.1-SNAPSHOT
[INFO] +- org.springdoc:springdoc-openapi-ui:jar:1.5.2:compile
[INFO] | +- org.springdoc:springdoc-openapi-webmvc-core:jar:1.5.2:compile
[INFO] | | \- org.springdoc:springdoc-openapi-common:jar:1.5.2:compile
[INFO] | | +- io.swagger.core.v3:swagger-models:jar:2.1.6:compile
[INFO] | | +- io.swagger.core.v3:swagger-annotations:jar:2.1.6:compile
[INFO] | | +- io.swagger.core.v3:swagger-integration:jar:2.1.6:compile
[INFO] | | | \- io.swagger.core.v3:swagger-core:jar:2.1.6:compile
[INFO] | | | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile
[INFO] | | | | \- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] | | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.12.3:compile
[INFO] | | | \- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | | +- io.github.classgraph:classgraph:jar:4.8.69:compile
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] | +- org.webjars:swagger-ui:jar:3.38.0:compile
[INFO] | \- org.webjars:webjars-locator-core:jar:0.46:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.12.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.5.0:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.5.0:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.5.0:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.14.1:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | | +- org.springframework:spring-core:jar:5.3.7:compile
[INFO] | | | \- org.springframework:spring-jcl:jar:5.3.7:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.28:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.5.0:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.3:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.3:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.3:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.3:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.12.3:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.5.0:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.46:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.46:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.46:compile
[INFO] | +- org.springframework:spring-web:jar:5.3.7:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.3.7:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.3.7:compile
[INFO] | +- org.springframework:spring-aop:jar:5.3.7:compile
[INFO] | +- org.springframework:spring-context:jar:5.3.7:compile
[INFO] | \- org.springframework:spring-expression:jar:5.3.7:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-couchbase:jar:2.5.0:compile
[INFO] | \- org.springframework.data:spring-data-couchbase:jar:4.2.1:compile
[INFO] | +- org.springframework:spring-context-support:jar:5.3.7:compile
[INFO] | +- org.springframework:spring-tx:jar:5.3.7:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:2.5.1:compile
[INFO] | \- com.couchbase.client:java-client:jar:3.1.5:compile
[INFO] | \- com.couchbase.client:core-io:jar:2.1.5:compile
[INFO] | \- io.projectreactor:reactor-core:jar:3.4.6:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.5.0:runtime (optional)
[INFO] | +- org.springframework.boot:spring-boot:jar:2.5.0:compile
[INFO] | \- org.springframework.boot:spring-boot-autoconfigure:jar:2.5.0:compile
[INFO] \- org.projectlombok:lombok:jar:1.18.20:compile (optional)
谢谢。
在 spring-projects/spring-data-couchbase
中提出了一个错误
https://github.com/spring-projects/spring-data-couchbase/issues/1155
它将在未来的版本中修复。
我正在尝试使用连接到 couchbase 的 @Query 注释执行自定义查询,我期待寻呼响应。
我有如下代码
控制器
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@GetMapping("/getEmployees/{page}/{size}")
public Page<Employee> getEmployees(@PathVariable int page, @PathVariable int size) {
Pageable pageable = PageRequest.of(page, size);
return employeeRepositoryTwo.findEmployeeDetails(pageable);
}
存储库
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.couchbase.repository.Query;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface EmployeeRepositoryTwo extends CouchbaseRepository<Employee, Integer> {
Employee findByEmpName(String empName);
Page<Employee> findByEmpName(String empName, Pageable pageable);
@Query("#{#n1ql.selectEntity} WHERE empName='Ravi'")
Page<Employee> findEmployeeDetails(Pageable pageable);
}
接电话
"http://localhost:8080/getEmployees/1/2"
我得到
java.lang.ArrayIndexOutOfBoundsException: 0
org.springframework.data.repository.query.ExtensionAwareQueryMethodEvaluationContextProvider.lambda$collectVariables[=14=](ExtensionAwareQueryMethodEvaluationContextProvider.java:116)
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)\r\n\tat java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:175)\r\n\tat java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:899)
.
.
而且我能够得到这个方法调用的响应
Page<Employee> findByEmpName(String empName, Pageable pageable);
所以当我使用如下所示的可分页注释的@Query 时,问题就来了
@Query("#{#n1ql.selectEntity} WHERE empName='Ravi'")
Page<Employee> findEmployeeDetails(Pageable pageable);
我的依赖树
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ couchbase ---
[INFO] com.ravi:couchbase:jar:0.0.1-SNAPSHOT
[INFO] +- org.springdoc:springdoc-openapi-ui:jar:1.5.2:compile
[INFO] | +- org.springdoc:springdoc-openapi-webmvc-core:jar:1.5.2:compile
[INFO] | | \- org.springdoc:springdoc-openapi-common:jar:1.5.2:compile
[INFO] | | +- io.swagger.core.v3:swagger-models:jar:2.1.6:compile
[INFO] | | +- io.swagger.core.v3:swagger-annotations:jar:2.1.6:compile
[INFO] | | +- io.swagger.core.v3:swagger-integration:jar:2.1.6:compile
[INFO] | | | \- io.swagger.core.v3:swagger-core:jar:2.1.6:compile
[INFO] | | | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile
[INFO] | | | | \- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] | | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.12.3:compile
[INFO] | | | \- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | | +- io.github.classgraph:classgraph:jar:4.8.69:compile
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] | +- org.webjars:swagger-ui:jar:3.38.0:compile
[INFO] | \- org.webjars:webjars-locator-core:jar:0.46:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.12.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.5.0:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.5.0:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.5.0:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.14.1:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | | +- org.springframework:spring-core:jar:5.3.7:compile
[INFO] | | | \- org.springframework:spring-jcl:jar:5.3.7:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.28:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.5.0:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.3:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.3:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.3:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.3:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.12.3:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.5.0:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.46:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.46:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.46:compile
[INFO] | +- org.springframework:spring-web:jar:5.3.7:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.3.7:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.3.7:compile
[INFO] | +- org.springframework:spring-aop:jar:5.3.7:compile
[INFO] | +- org.springframework:spring-context:jar:5.3.7:compile
[INFO] | \- org.springframework:spring-expression:jar:5.3.7:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-couchbase:jar:2.5.0:compile
[INFO] | \- org.springframework.data:spring-data-couchbase:jar:4.2.1:compile
[INFO] | +- org.springframework:spring-context-support:jar:5.3.7:compile
[INFO] | +- org.springframework:spring-tx:jar:5.3.7:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:2.5.1:compile
[INFO] | \- com.couchbase.client:java-client:jar:3.1.5:compile
[INFO] | \- com.couchbase.client:core-io:jar:2.1.5:compile
[INFO] | \- io.projectreactor:reactor-core:jar:3.4.6:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.5.0:runtime (optional)
[INFO] | +- org.springframework.boot:spring-boot:jar:2.5.0:compile
[INFO] | \- org.springframework.boot:spring-boot-autoconfigure:jar:2.5.0:compile
[INFO] \- org.projectlombok:lombok:jar:1.18.20:compile (optional)
谢谢。
在 spring-projects/spring-data-couchbase
中提出了一个错误https://github.com/spring-projects/spring-data-couchbase/issues/1155
它将在未来的版本中修复。