title: JPA/hibernate subquery in from clause
body: <p>We're using JPA with hibernate as the provider,
  we have a query that contains a join with a subquery in the FROM clause, but we get the following error:</p>
  
  <blockquote>
    <p>org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near
    line 1, column 75 [SELECT sd FROM
    com.hp.amber.datamodel.entities.analysis.SnapshotDates sd, (SELECT
    max(x.changeDate) maxChangeDate, x.viewId, x.state FROM
    com.hp.amber.datamodel.entities.analysis.SnapshotDates x WHERE
    x.changeDate&lt;:date AND x.viewId in (:viewIds) AND x.state=:state GROUP
    BY x.viewId, x.state) sd2 WHERE sd.viewId = sd2.viewId AND sd.state =
    :state AND sd.changeDate = sd2.maxChangeDate]</p>
  </blockquote>
  
  <p>This is the query:</p>
  
  <pre><code>SELECT sd 
  FROM SnapshotDates sd, 
       (SELECT max(x.changeDate) maxChangeDate, x.viewId, x.state 
        FROM SnapshotDates x
       WHERE x.changeDate&lt;:date AND x.viewId in (:viewIds) AND x.state=:state
  GROUP BY x.viewId, x.state) sd2
  WHERE sd.viewId = sd2.viewId 
        AND sd.state = :state 
        AND sd.changeDate = sd2.maxChangeDate
  </code></pre>
  
  <p>Thank you for helping</p>