title: JPA native query generation with COUNT (DISTINCT obj)
body: <p>please help me with JPQL Query on OpenJPA 1.2.x
  Here is the text of my query:</p>
  
  <blockquote>
    <p>select count (distinct evt) from Event
    evt WHERE (evt.beginDate >=
    :startOfPeriod and evt.beginDate &lt;=
    :endOfPeriod)  ORDER BY evt.beginDate
    asc</p>
  </blockquote>
  
  <p>At runtime I get an error:</p>
  
  <blockquote>
    <p>
    org.apache.openjpa.persistence.ArgumentException:
    DB2 SQL Error: SQLCODE=-119,
    SQLSTATE=42803 , SQLERRMC=BEGIN_DATE,
    DRIVER=3.59.81 {prepstmnt 1520523937
    SELECT COUNT(DISTINCT t0.ID),
    t0.BEGIN_DATE
        FROM COMPANY.EVENT t0
        WHERE (t0.BEGIN_DATE >= ? AND t0.BEGIN_DATE &lt;= ?) optimize for 1 row
    [params=(Timestamp) 2010-12-14
    00:00:00.0, (Timestamp) 2010-12-14
    23:59:59.999]} [code=-119,
    state=42803]</p>
  </blockquote>
  
  <p>Why does JPA prints field <strong>t0.BEGIN_DATE</strong> in select clause? 
  Why did JPA miss ORDER BY clause in native SQL?
  For example, this query (without t0.BEGIN_DATE in select clause) is valid:</p>
  
  <pre><code>SELECT COUNT(DISTINCT t0.ID) 
      FROM CALENDAR.EVENT t0
      WHERE (t0.BEGIN_DATE &gt;= null AND t0.BEGIN_DATE &lt;= null)
  </code></pre>
  
  <p><em>I've set null just for successful SQL query execution</em></p>
  
  <p>Is it a some kind of a bug?</p>