Issue
I have encountered a problem with union mapping to view in Spring Data JPA.
Error:
Error:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type path.PlayerAccountView
My current implementation:
@Query(
value = """
SELECT user_uid, operator_uid FROM player_account_table_one WHERE job_id = :sessionId
UNION
SELECT user_uid, operator_uid FROM player_account_table_two WHERE job_id = :sessionId
UNION
SELECT user_uid, operator_uid FROM player_account_table_three WHERE job_id = :sessionId
UNION
SELECT user_uid, operator_uid FROM player_account_table_four WHERE job_id = :sessionId
UNION
SELECT user_uid, operator_uid FROM player_account_table_five WHERE job_id = :sessionId
UNION
SELECT user_uid, operator_uid FROM player_account_table_six WHERE job_id = :sessionId
""",
nativeQuery = true,
)
fun findUsersViewResult(@Param("sessionId") sessionId: Long): List<PlayerAccountView>
View class:
data class PlayerAccountView(
val playerUid: String = Nil.String,
val operatorUid: String = Nil.String,
)
Solution
You have 2 options to avoid this exception:
1-Define and reference a @NamedNativeQuery with an @SqlResultSetMapping. 2-Use a fragment interface to provide your own implementation of a repository method.
Answered By - Amer Al Munajjed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.