title: Hibernate AliasToBean with Collection
body: <p>I have a bi-directional one-to-many relationship defined between Parent and Child classes. I'm looking to execute a query such that I can return a single parent, and a subset of its children in a bean.</p>
  
  <pre><code>public class Parent {
      private int id;
      private Set&lt;Child&gt; children = new HashSet&lt;Child&gt;(0);
  
      // other fields + getters and setters
  }
  
  public class Child {
      private Parent parent;
      private int age;
  
      // other fields + getters and setters
  }
  </code></pre>
  
  <p>The output I'm looking to achieve is:</p>
  
  <pre><code>public class ParentChildWrapper {
      private Parent parent;
      private Collection&lt;Child&gt; children; // subset of children
  }
  </code></pre>
  
  <p>I'd like to filter on the parent's id and the child's age column. I've tried a number of query combinations in order to get the desired output.</p>
  
  <p>The following is close, but doesn't group the children in a collection in the ParentChildWrapper bean I've defined. The result I get is a list of objects, with 1 instance per child that matches the age filter:</p>
  
  <pre><code>Query q = session.createQuery(
      "SELECT p, c " +
      "FROM Parent p " +
      "INNER JOIN p.children c " +
      "WHERE p.id = :id " +
      "AND c.age = :age"
  );
  </code></pre>
  
  <p>I've also tried to group by the parent in order to try and aggregate all the children into a collection, also to no avail.</p>
  
  <p>Obviously I could separate this into two separate queries in order to select the parent, and then select the children that I want. But it feels like this should be a fairly common use case. Perhaps I'm not thinking in a hibernate-esque way.</p>