title: Criteria api equivalent for joining child with parent
body: <p>Version: Hibernate 3.3</p>
  
  <p>Hi,
    I have 2 simple models:</p>
  
  <pre><code>class Parent {
    Long id; //auto generated sequence and primary key
    String name;
    Set&lt;Child&gt; children;
  }
  
  class Child {
    Long id;
    String name;
    Parent parent; 
  }
  </code></pre>
  
  <p>with the following hbm:</p>
  
  <pre><code>&lt;class name="my.Parent" table=PARENT"&gt;
    &lt;id name="id" column="PARENT_ID" type="java.lang.Long"&gt;
    &lt;property name="name" column="NAME" type="java.lang.String"&gt;
    &lt;set name="children" table="CHILDREN" inverse="true"&gt;
          &lt;key&gt;&lt;column name="PARENT_ID" not-null="true" /&gt;&lt;/key&gt;
          &lt;one-to-many class="my.Child" /&gt;
    &lt;/set&gt;
  &lt;/class&gt;
  
  &lt;class name="my.Child" table=CHILD"&gt;
    &lt;composite-id&gt;
      &lt;key-many-to-one name="parent" column="PARENT_ID" class="my.Parent" /&gt;
      &lt;key-property name="id" column="CHILD_ID" type="java.lang.Long" /&gt;
    &lt;/composite-id&gt;
    &lt;property name="name" column="NAME" type="java.lang.String"&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>What I want to achieve is this: "select all children whose parent's name is 'John'. I am not able to figure out how to write Criteria api equivalent for a hql that looks like this:</p>
  
  <pre><code>SELECT child
  FROM Child as child join child.parent 
  where parent.name = 'John'
  </code></pre>
  
  <p>I tried the below one but its not generating the expected join query:</p>
  
  <pre><code>Criteria c = session.createCriteria(Child.class);
  c.createCriteria("parent").add(Restrictions.eq("name", "John");
  c.list();
  </code></pre>
  
  <p>Could anybody see what am I doing wrong?</p>
  
  <p>Any ideas would be greatly appreciated.  </p>