4

Most of the examples I've seen is using entityManager.createQuery or .createNativeQuery etc.

Is there a way to have something like the following working?

data class SummaryDto(val employeeName: String, val employerName: String)

@Query("select e.name as employeeName, emp.name as employerName " +
            "from Employer e " +
            "inner join Employee emp on emp.employer_id = e.id ", nativeQuery = true)
    fun findSummaries(): List<SummaryDto>

When I ran the above code

I got this error No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [dto.SummaryDto]

Can this be done with Kotlin or is there another way to get this to work with Hibernate JPA Annotation based?

Thanks Tin

0

1 Answer 1

8

For anyone that might run into the same problem. Change SummaryDto to an interface like this

interface SummaryDto { val employeeName: String val employerName: String }

will work.

Sign up to request clarification or add additional context in comments.

1 Comment

But why it works?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.