title: JPA: ordering query results by collection valued property?
body: <p>I have an entity that has dollection-valued property:</p>
  
  <pre><code>@Entity
  public class Scenario{
    ..
    @ManyToMany
    List&lt;Category&gt; categories;
    ..
  }
  </code></pre>
  
  <p>Is there any way to query for <code>Scenarios</code> and order query results for <code>categories</code> property, something like this:</p>
  
  <p><code>select scenario from Scenario scenario order by scenario.category</code></p>
  
  <p>More precisely, we are interested in sorting for first category from each <code>Scenario</code>'s list and ignoring the rest of them. Can we do such things in JPQL/Criteria queries (eg. passing custom <code>Comparator</code> somehow)?</p>