subquery « Fetch « JPA Q&A





1. How to retrieve the result of a subquery with Criteria API?    forum.hibernate.org

@Entity public class Company implements Serializable { ... } @Entity public class Employee implements Serializable { private Company company; @ManyToOne public Company getCompany() { return company; } ... } ...

2. Correlated subquery with FETCH    forum.hibernate.org

SELECT t FROM Transmission t JOIN FETCH t.parent JOIN FETCH t.parent.course JOIN FETCH t.year.sem WHERE t.if_active = 'N' AND t.year = :P_YEAR AND 1 > ( select count(*) FROM Instances act JOIN FETCH act.transmission JOIN FETCH act.transmission.parent JOIN FETCH act.year JOIN FETCH act.year.sem WHERE act.nr = :P_NR AND act.transmission.parent.emp = t.parent.emp AND act.year.sem = t.year.sem )