kavi
kavi

Reputation: 172

Spring data JPA - 1.5 convert result into non - entity POJO class

I am using Spring data JPA version 1.5

@SqlResulttSetMapping IS NOT SUPPORTABLE IN VERSION LOWER THAN

SELECT 
bc.badge_id , bc.badge_progress , bc.badge_level, bc.badge_unique_key , 
b.badge_name , b.badge_type , b.how_to_earn , b.description , b.unit ,
b.level1_milestone , b.level2_milestone , b.level3_milestone , b.image_url
FROM badge_calculation bc 
INNER JOIN badges b ON b.id = bc.badge_id
where bc.user_id = '3';

There are two tables in Database and I want some columns from both of them and want to map result into non - entity POJO class. It contains fields which i required from both tables. Is there any solution ?

Upvotes: 0

Views: 361

Answers (1)

RobOhRob
RobOhRob

Reputation: 585

In the repository, you could do something like this. You can receive a list of object arrays that you can then iterate through and do whatever you like with them. Execute this query and put a breakpoint afterwords to inspect the list and see the field types.

@Query( value = ""
        + " SELECT  "
        + "bc.badge_id , bc.badge_progress , bc.badge_level, bc.badge_unique_key ,  "
        + "b.badge_name , b.badge_type , b.how_to_earn , b.description , b.unit , "
        + "b.level1_milestone , b.level2_milestone , b.level3_milestone , b.image_url "
        + "FROM badge_calculation bc  "
        + "INNER JOIN badges b ON b.id = bc.badge_id "
        + "where bc.user_id = :userId", nativeQuery = true )
List<Object[]> runThisHere(  @Param( "userId" ) int userId);

Upvotes: 1

Related Questions