title: JPQL / JPA query to order entities based on the greatest/maximum of two columns?
body: <p>I need something similar to this SQL query:</p>
  
  <pre><code>SELECT * FROM foo f ORDER BY GREATEST(f.bar_date, f.baz_date)
  </code></pre>
  
  <p>As not all RDBMS systems support the <code>GREATEST</code> function, ideally I would like the JPA implementation to generate the correct SQL query for the underlying database. The databases that I am targetting are Oracle, SQL Server, and PostgreSQL.</p>