Search code examples
javajpatoplink

JPA Nested Select Left Outer Join


Is it possible to do a nested select in JPA QL?

How would I write the following SQL statement in JPA QL?

select * from preferences p left outer join (select * from preferencesdisplay where user_id='XXXX') display on ap.pref_id=display.pref_id;

The JPA entity PREFERENCES has a OneToMany relationship to PREFERENCESDISPLAY. I want to get all the PREFERENCES whether or not there is a PREFERENCESDISPLAY reference.


Solution

  • In hibernate you can use "with":

    select ... from Preferences p left join p.displays d  with  d.user.id = 100
    

    But in JPA I have never seen such possibilities.