spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

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

Open spring-projects-issues opened this issue 5 years ago • 2 comments

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

spring-projects-issues avatar Nov 11 '19 14:11 spring-projects-issues

This is still an issue!

dkraemerwork avatar Feb 09 '22 09:02 dkraemerwork

This shouldn't be the case on recent versions? If someone was willing to make the example work with a recent Boot / Gradle version (I spent 30 minutes on that but was unable to get it to work), I'm willing to investigate.

odrotbohm avatar Feb 18 '22 13:02 odrotbohm