title: JPA NamedNativeQuery syntax error with Hibernate, PostgreSQL 9
body: <p>I am having a rather odd problem. I have native query which runs perfectly when executed on sql server:</p>
  
  <pre><code>SELECT  date_time, GREATEST(sum(count_up - count_down) OVER (PARTITION BY date_trunc('day', result.date_time) ORDER BY date_time),0) AS cum_amt FROM   peoplecounting.result order  BY date_time;
  </code></pre>
  
  <p>However, using this query as native query in JPA results in syntax error</p>
  
  <pre><code>@NamedNativeQueries({@NamedNativeQuery(
          name = "Result.getTotal",
          query = "SELECT  date_time, GREATEST(sum(count_up - count_down) OVER (PARTITION BY date_trunc('day', peoplecounting.result.date_time) ORDER BY date_time),0) AS cum_amt FROM   peoplecounting.result order  BY date_time;")})
  
  public class Result implements Serializable {...
  </code></pre>
  
  <p>///</p>
  
  <pre><code>@Entity
  @SqlResultSetMapping(name = "TotalResultMapping", entities = {@EntityResult(entityClass = TotalResult.class, fields = {@FieldResult(name = "total", column = "cum_amt"), @FieldResult(name = "date", column = "date_time")})})
  
  public class TotalResult {
  
  private static final long serialVersionUID = 1L;
  
  public TotalResult() {
  }
  
  
  @Id Date date;
  
  public Date getDate() {
      return date;
  }
  
  public void setDate(Date date) {
      this.date = date;
  }
  
  public Integer getTotal() {
      return total;
  }
  
  public void setTotal(Integer total) {
      this.total = total;
  }
  
  Integer total;
  </code></pre>
  
  <p>}</p>
  
  <p>When calling:  <code>em.createNativeQuery("Result.getTotal","TotalResultMapping").getResultList();</code></p>
  
  <p>I get:</p>
  
  <pre><code>INFO  [stdout] (default task-44) Hibernate: Result.getTotal
  WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-44) SQL Error: 0, SQLState: 42601
  ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-44) Error: Syntax error at or near "Result"
  </code></pre>