I am new to JPA and trying to do a left outer join, only if a condition is satisfied in the native JPA query.
Native query is as shown below. Here I would like to do A left outer join B
with the where condition, only if a given flag toJoin
is true in application:
select a.id, a.name from A left outer join B on A.id = B.aid where b.name="some_name"
I am not sure, how will I accommodate the toJoin
application flag in the above native JPA query in my JPA repository.
EDIT
I was just trying to achieve the same in mysql with the help of CASE WHEN
and sample condition as follows:
select a.id from A a, case when 1=2 then left outer join B b ON a.id = b.aid end limit 2;
But I am getting syntaxt error.