title: JPA left join to find unused entries
body: <p>I'm sure I'm being stupid but I can't seem to figure this one out...</p>
  
  <p>I have two tables:</p>
  
  <p>department( did, name )
  employee( eid, first, last, did )</p>
  
  <p>they have corresponding entities JPA managed entites Department and Employee. Employee has a Deparment field, Department doesn't maintain an Employee list. What I want to do though is find all the Departments that have no Employees. Using plain old SQL this is easy with a left join:</p>
  
  <pre><code>SELECT d.* 
  FROM department as d LEFT OUTER JOIN employee as e
  ON d.did = e.did
  WHERE e.did IS NULL
  </code></pre>
  
  <p>I can't see how to translate this query into JPQL though. All the examples I've found for JPQL left joins traverse the link the other way, for example.</p>
  
  <pre><code>SELECT e FROM Employee e LEFT JOIN e.departmert d
  </code></pre>
  
  <p>Whereas I need something more like</p>
  
  <pre><code>SELECT d FROM Department d LEFT JOIN d.???? WHERE e.department IS NULL
  </code></pre>
  
  <p>but the department doesn't maintain a reference to it's employees (in my application it's not departments and employees obviously). Is this even possible in JPQL?</p>