Search code examples
spring-bootspring-data-jpacrudcouchbasespring-data-couchbase

Spring Data Couchbase with @Query and Pageable / Sort throwing ArrayIndexOutOfBoundsException - PagingAndSortingRepository, CouchbaseRepository


I am trying to execute custom query with @Query annotation which is connecting to couchbase and I am expecting paging response.

I have code like below

Controller

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);
    } 

Repository

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);
}

Get Call

"http://localhost:8080/getEmployees/1/2"

I am getting

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)\r\n\tat java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)\r\n\tat java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:899)
.
.

And I am able to get response for this method call

Page<Employee> findByEmpName(String empName, Pageable pageable); 

So problem comes when I have @Query annotated with pageable like below

 @Query("#{#n1ql.selectEntity} WHERE empName='Ravi'")
        Page<Employee> findEmployeeDetails(Pageable pageable);

My dependency tree

[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) 

Thanks.


Solution

  • Raised a bug in spring-projects/spring-data-couchbase

    https://github.com/spring-projects/spring-data-couchbase/issues/1155

    It will fixed in upcoming versions.