I have this structure from entities Aa, Bb, Cc:
- Aa has a list of Bb
- Bb has a list of Cc
–
public class Aa{
@OneToMany
List<Bb> listBb;
}
public class Bb{
@OneToMany
List<Bb> listCc;
}
I would like to create a JPA Criteria API query to pool Aa by an id of C:
public A getAaByCcId(long id) {...}
In native sql I would have try left join (twice). How do I do this using JPA?
You also do it with joins in JPQL:
Note that inner joins can be used here, since you have a restriction on
c.id = :cId, which can only be true if B and C exist. But you could use left joins as well.EDIT:
Using a Criteria query, it would look like the following (not tested):