title: Hibernate-Criteria: Select distinct column from table ordered by another column
body: <p><strong>What I want to achieve:</strong> Get list of unique ids ordered by another column, using Hibernate Criteria.</p>
  
  <p><strong>My code so far:</strong></p>
  
  <pre><code> Criteria crt = createCriteria(); //complex method returning Criteria
                                    //with joined tables, restrictions and ordering
   crt.setProjection( Projections.distinct( Projections.property( "id")));
   List&lt;Integer&gt; ids = crt.list();
  </code></pre>
  
  <p><strong>What is wrong:</strong> When I set order by column let's say "date" I get query:</p>
  
  <pre><code>SELECT DISTINCT id FROM table \\JOIN, WHERE...\\ ORDER BY date);
  </code></pre>
  
  <p>which is obviously wrong and results in error:</p>
  
  <pre><code>ORA-01791: not a SELECTed expression
  </code></pre>
  
  <p><strong>My idea how to solve it:</strong> Somehow force Hibernate to generate this query:</p>
  
  <pre><code>SELECT DISTINCT id FROM (SELECT * FROM table \\JOIN, WHERE...\\ ORDER BY date);
  </code></pre>
  
  <p><strong>Problems and what I tried:</strong> There is <code>createCriteria()</code> method, which I don't want to modify if it's not absolutely necessary. I didn't find a way to use this Criteria as DetachedCriteria.</p>