title: JPQL navigate through several nested objects for comparison
body: <p>So, I'm creating a search function to find a post containing bookitems where one bookitem contains a book with a specific title. </p>
  
  <p>I've tried this query:</p>
  
  <pre><code>SELECT p FROM Post p JOIN p.books b JOIN FETCH b.book bo WHERE bo.title LIKE '%hi%'
  </code></pre>
  
  <p>where books is a list of BookItems containing one Book each</p>
  
  <p>And that works if I'm running the JPQL from netbeans towards the server but when i use the same query with the EntityManager i recieve an exception that bo after b.book was an unexpected symbol. But i really don't now how else to do it.</p>
  
  <p><strong>EDIT</strong>
  Aditional info:
  stacktrace:</p>
  
  <pre><code>    Caused by: Exception [EclipseLink-8025] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JPQLException
  Exception Description: Syntax error parsing the query [SELECT p FROM Post p JOIN p.books b JOIN FETCH b.book bo WHERE bo.title LIKE :title], line 1, column 54: unexpected token [bo].
  Internal Exception: NoViableAltException(80@[()* loopback of 477:9: (node= join )*])
  </code></pre>
  
  <p>if i try with fetch after first JOIN it prints the same error but on b instead of bo</p>
  
  <p>Code when running JPQL:</p>
  
  <pre><code>query = em.createQuery("SELECT p FROM Post p JOIN p.books b JOIN FETCH b.book bo WHERE bo.title LIKE :title", Post.class);
  query.setParameter("title", "%"+searchString+"%");
  posts = query.getResultList();
  </code></pre>