I am stuck in a problem where I am not able to find out how to generate a left outer join on two tables using criteriaQuery. I have two table A_1 and A_2
@Entity()
@Table(name = "A_1")
public class A1 {
private long id_1;
private long name;
private long city;
}
@Entity()
@Table(name = "A_2")
public class A2 {
private long id_2;
private long a_1_id_1;
private long name;
}
I have to find out all those entry which are present in A_1 table but not in A_2 table. id_1 in A_1 table is same as a_1_id_1.
For this I am trying query like:
select * from A_1 LEFT OUTER JOIN A_2 ON A_1.id_1 = A_2.a_1_id_1 where A_2.a_1_id_1 is NULL
I am getting desired results from my query. But I am not able to find out how Can I change it to code, basically this left outer join part. I have tried lots of options from net but unable to find out the solution.
My code is something like this:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> query = cb.createTupleQuery();
Root<A_1> root1 = query.from_1(A_1.class);
Root<A_2> root2 = query.from(A_2.class);
List<Predicate> predicates = getPredicates(cb, root1, root1, request);
I am not able to decide how can I use this to get my desired results. Thanks in advance.