Reputation: 83
I'm new to spring boot so I was wondering how do I join and return a dataset from multiple entities using native query. Like
Select p.a, q.b, r,c from table1 p, table2 q, table3 r where p.id = q.id and q.flag = r.flag;
Any help is appreciated :)
Upvotes: 0
Views: 543
Reputation: 2953
You can use custom object in JPQL to pass these values or use object array.
Create a class with constructor taking these arguments.
Example:
@Query(value = "Select new com.path.to.class.Aggregate(p.a, q.b, r.c)
from table1 p, table2 q, table3 r where p.id = q.id and q.flag = r.flag")
Or use List<Object[]>
as return type. The first element in list will contain these 3 objects.
Upvotes: 1