#spring-boot #spring-data-jpa #crud #couchbase #spring-data-couchbase
Вопрос:
Я пытаюсь выполнить пользовательский запрос с аннотацией @Query, которая подключается к couchbase, и я ожидаю ответа на подкачку.
У меня есть код, как показано ниже
Контроллер
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$0(ExtensionAwareQueryMethodEvaluationContextProvider.java:116)
java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)rntat java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)rntat 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)
Спасибо.
Ответ №1:
Выявлена ошибка в spring-проектах/spring-data-couchbase
https://github.com/spring-projects/spring-data-couchbase/issues/1155
Это будет исправлено в следующих версиях.