0

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 ?

kavi
  • 172
  • 1
  • 14
  • You can create view in database and map that view with newly created class with same field of view. – Sanjay Feb 26 '19 at 16:04
  • Are you doing this in the repository? – RobOhRob Feb 26 '19 at 17:20
  • Possible duplicate of [How to use Constructor Mapping with Spring JPA Repositories](https://stackoverflow.com/questions/30989315/how-to-use-constructor-mapping-with-spring-jpa-repositories) – Alan Hay Feb 26 '19 at 17:55
  • Or you can use Spring Data projections, the usage of which is covered in the reference manual. – Alan Hay Feb 26 '19 at 17:56
  • @Sanjay There is lots of data - view might causes performance issue. – kavi Feb 27 '19 at 06:54
  • @RobOhRob no, this is just a query I want to get result using Spring data Jpa version 1.5 – kavi Feb 27 '19 at 06:55
  • @AlanHay no, it is a solution for higher version of spring data jpa. I'm asking for lower version – kavi Feb 27 '19 at 09:53

1 Answers1

1

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);
RobOhRob
  • 585
  • 7
  • 17