title: JPA, left outer join on the same table
body: <p>How can I execute left outer join in JPA with the same table? When I try this:</p>
  
  <pre><code>sql.append("SELECT e1 FROM ");
  sql.append(getPersistentClass().getName());
  sql.append(" e1 LEFT OUTER JOIN ");
  sql.append(getPersistentClass().getName());
  sql.append(" e2 ON e1.username = e2.username AND e1.radacctid &lt; e2.radacctid ");
  sql.append("WHERE e2.radacctid IS NULL ");
  sql.append("AND e1.acctstoptime IS NOT NULL ");
  sql.append("AND DATEDIFF(NOW(), e1.acctstoptime) &gt; ?1");
  </code></pre>
  
  <p>I get error: "unexpected token: ON near line 1, column 122 [SELECT e1 FROM com.homersoft.wh.db.entity.radius.RadAcct e1 LEFT OUTER JOIN com.homersoft.wh.db.entity.radius.RadAcct e2 ON e1.username = e2.username AND e1.radacctid &lt; e2.radacctid WHERE e2.radacctid IS NULL AND e1.acctstoptime IS NOT NULL AND DATEDIFF(NOW(), e1.acctstoptime) > ?1]"</p>