title: How to formulate a JOIN in a typed query?
body: <p>I want to create a typed query.</p>
  
  <pre><code>TypedQuery&lt;PubThread&gt; query = em.createQuery(queryString, PubThread.class);
  query.setParameter("threadId", threadId);
  List&lt;PubThread&gt; otherPubThreads = query.getResultList();
  </code></pre>
  
  <p>In the queryString is the following SQL (currently without param and static selection values)</p>
  
  <pre><code>SELECT pt2 FROM pubthread pt2   
  JOIN pub_pubthread ppt2 ON pt2.id = ppt2.pubThreads_id  
  JOIN pub p2 ON ppt2.pups_id = p2.id     
  JOIN pubcategory pc2 ON p2.pubCategoryId = pc2.id   
  WHERE pt2.id != 1 and EXISTS (      
      SELECT DISTINCT(pt.id) 
      FROM pubthread pt       
      JOIN pub_pubthread ppt ON pt.id = ppt.pubThreads_id         
      JOIN pub p ON ppt.pups_id = p.id        
      JOIN pubcategory pc ON p.pubCategoryId = pc.id      
      WHERE pc2.id = pc.id and pt.id = 1  
  )
  </code></pre>
  
  <p>It does work, if I limit the String to a simple select: <code>SELECT Distinct(pt2.id), pt2.name FROM pubthread pt2</code>. As soon I add a JOIN line to it, it will complain. How do you properly query with JOINS in JPA? The error is: 
  <code>org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ON near line 1, column 81 [SELECT pt2 FROM com.brayan.webapp.model.PubThread pt2 JOIN pub_pubthread ppt2 ON pt2.id = ppt2.pubThreads_id ]</code></p>
  
  <p>Doubtless, a criteria query would be nicer. I accept that as part of the solution space.</p>