title: Hibernate: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 6...)
body: <p>I state that I am using Hibernate, MySQL on Mac OSX.</p>
  
  <p>I read the post that concerned my problem but unfortunately I could not solve it. Below place the code in question:</p>
  
  <pre><code>public List&lt;FeedMessage&gt; getLatestFeedMessage() {
      List&lt;FeedMessage&gt; messages = new ArrayList&lt;&gt;();
  
      String hql = "from (select nomeFeed, title, max(pubDate) as maxdate "
                    + "from FeedMessage group by nomeFeed) as x inner join FeedMessage as f "
                                      + "on f.nomeFeed = x.nomeFeed and f.pubDate = x.maxdate";
  
  
      System.out.println(hql);
      try {
          session = HibernateUtil.getSessionFactory().openSession();
          Query query = session.createQuery(hql);
          messages=query.list();
      } catch (QueryException e) {
          e.printStackTrace();
      } finally {
          if(session.isOpen())
          session.close();
      }
  
      return messages;
  
  }
  </code></pre>
  
  <p>I'm trying to select from a MySQL db the first line of each group, but I get the following error:</p>
  
  <pre><code>org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column 6 [from (select nomeFeed, title, max(pubDate) as maxdate from it.unirc.fantapjam.FeedMessage.Model.FeedMessage group by nomeFeed) as x inner join FeedMessage as f on f.nomeFeed = x.nomeFeed and f.pubDate = x.maxdate]
  at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
      at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:126)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:88)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
      at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
      at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
      at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1796)...........
  </code></pre>
  
  <p>I think the problem is that Hibernate can not translate the query because, if I run directly to MySQL, this works. Alternatively, I tried to run the sequent query:</p>
  
  <pre><code>String hql = "from (select nomeFeed, title, max(pubDate) as maxdate "
                                      + "from FeedMessage "
                                      + "group by nomeFeed) as x,  FeedMessage as f "
                      + "where f.nomeFeed = x.nomeFeed and f.pubDate = x.maxdate";
  </code></pre>
  
  <p>but I get the same result.</p>