Hello friends, may anybody help me about custom Qu...
# spring
o
Hello friends, may anybody help me about custom Query using JpaRepository ? I do use this query:
Copy code
@Query("select id, email from User")
fun getAllIdsAndEmails(): List<Pair<Long, String>>
But sadly I get an error of
No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [kotlin.Pair<?, ?>]
Also tried
List<Tuple>
, still did not work
But the return type is like Pair this is example return [ [ 0, “x@gmail.com” ], [ 1, “a@mail.com” ] ]
g
Have you tried
List<User>
?
o
let me do it
but I am not selecting all required fields of user
Yeah it gave error
g
Have you tried something like this, using some list implementation:
fun getAllIdsAndEmails(): List<Long, String>
? Or, you could use something like they show here: https://faun.pub/select-specific-columns-from-a-database-table-using-spring-data-jpa-d4eb0a24a2c4 That it is similar to what I see in a Stack overflow thread Thats looks like the right path I think
o
Yes this did not work
p
I am not sure how to convert to a
Pair
but you can try this interface:
Copy code
interface UserData {
    val id: Long 
    val email: String?        
}
and then you will have
fun getAllIdsAndEmails(): List<UserData>
2
o
Ah yeah, that worked
Thanks
2798 Views