title: How can I query the average difference of dates in days using HQL (Hibernate)?
body: <p>I need to retrieve from my PostgreSQL database, which has been mapped to Java using Hibernate, the average difference of dates (start and end, as you may say) of the records.</p>
  
  <p>I wrote a native PostgreSQL query which works fine:</p>
  
  <pre><code>SELECT avg(date_part('days', age(datasaida, dataentrada))) as avg_days
    FROM processo.processo
    WHERE processo.codsituacao = '14'
    AND processo.dataEntrada &gt;=  now() - interval '30 days';
  </code></pre>
  
  <p>The problem is that I can't figure out how to translate this query to HQL (Hibernate SQL) because of the <code>avg(date_part('days', age(datasaida, dataentrada)))</code> part.</p>
  
  <p>I need the information to be shown in the front-end, which I am building with JSF Primefaces.</p>
  
  <p>P.S.: dataEntrada - means startDate <em>(kind of)</em>. dataSaida means endDate <em>(kind of)</em></p>