spring-projects / spring-projects/spring-data-commons

Error when returning Vavr collection from @Query projection [DATACMNS-1611]

Open
#2,040 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

type: bug
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

Ruben Gees opened DATACMNS-1611 and commented

We get an error when trying to return a Vavr collection from a JpaRepository containing only parts of the object.

One example of such an interface method is:

@Query("SELECT name FROM Todo")
fun findAllNamesVavr(): Seq<String>

This crashes with the stack trace:

java.lang.ClassCastException: class java.lang.String cannot be cast to class io.vavr.collection.Seq (java.lang.String is in module java.base of loader 'bootstrap'; io.vavr.collection.Seq is in unnamed module of loader 'app')
	at com.sun.proxy.$Proxy84.findAllNamesVavr(Unknown Source)
	at com.example.demospringdatavavr.TodoRepositoryTest.finding names vavr seq(TodoRepositoryTest.kt:45)

 
Reproduced starting with Spring Boot 2.1.0.RELEASE.

Reproduction project: https://github.com/rubengees/demo-spring-data-vavr

Run

./gradlew build 

We debugged into the relevant classes and found the QueryExecutionResultHandler to be a possible cause of this. It looked like the handler tries to convert the entire List (from hibernate) to the inner type (String) of the return Type (Seq<String>) instead of converting each inner element of the List (from hibernate)


Affects: 2.2.1 (Moore SR1)

1 votes, 2 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.