title: Hibernate sort entities by property of children mapped as Map<String, Child>
body: <p>Here is my model:</p>
  
  <pre><code>@Entity
  @Table(name = "parent")
  public class Parent {
  
      ...
  
      @OneToMany(fetch = FetchType.LAZY, orphanRemoval = true, cascade = { CascadeType.REMOVE}, mappedBy = "parent")
      @MapKeyColumn(name = "key")
      private Map&lt;String, Child&gt; children;
  
      ...
  
  }
  
  @Entity
  @Table(name = "child")
  public class Child {
  
      ...
  
      @Column(name = "key")
      private String key;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "parent_id")
      private Parent parent;
  
      @Column(name = "property")
      private String property;
  
      ...
  
  }
  </code></pre>
  
  <p>That mapping is usefull and works on inserting, updating, deleting entites and selecting them.</p>
  
  <p>Now I have to order Parent entites using their children property depending on map key, a something like <code>order by parent.children[&lt;particular key&gt;].property asc</code> clause(which I did not find in HQL). Also I have no idea how to achieve this using Criteria API. Any idea?</p>
  
  <p>Only solution I have now is to select Children filtered by <code>key</code> and ordered by <code>property</code> and then fetch parents in Java code one by one which is not efficient even with "fetch parent" set. </p>