title: Hibernate: One to many relation where clause
body: <p>I have two tables </p>
  
  <pre><code>Table 1 (Parent)
      parent_Id
      Name
  
  Table2 (Child)
      child_Id
      Name
      Parent_id
      version
  </code></pre>
  
  <p>Corresponding classes are</p>
  
  <pre><code>Class Parent
  {
      Int parentId;
      String name;
      Set&lt;Child&gt; childList;
  
      @Id
      @Column(name="PARENT_ID")
      public int getParentId()
      {
         return parentId;
      }
     @Column(Name="NAME"
     public String getName()
     {
       return name;
     }
     @OneToMany(mappedBy="parent",fetch=FetchType.EAGER)
     @OrderBy("pareantId")
  
     public Set&lt;Child&gt; getChildList()
     {
        return childList;
     }
  
  }
  
     Class Child {
        Int childId;
      String name;
      Parent parent;
      int age;
  
      @Id
      @Column(name="CHILD_ID")
      public int getId()
      {
         return childId;
      }
     @Column(Name="NAME"
     public String getName()
     {
       return name;
     }
     @ManyToOne
     @JoinColumn(name = "PARENT_ID", nullable = false) 
     public A getParent()
     {
        return parent;
     }
  
     public getAge()
     {
       return age;
     }
  </code></pre>
  
  <p>}
  This is my DAO class which is working fine if I just use in query (from parent where parentId=1).</p>
  
  <pre><code>@Transactional
      public Parent getParentBy(int id) 
      {
          Parent parent = null;
          Session session = this.sessionFactory.getCurrentSession();
          try{
          parent =(Parent) session.createQuery("from Parent where parentId=? ).setParameter(0,id).uniqueResult();
  
          } catch (Exception e)
          {
              e.printStackTrace();
          }
          return parent;
      }
  </code></pre>
  
  <p>When I am running this I am getting all the childs under that parent in the set.</p>
  
  <p>Now, what I need to do if I want to add the where clause for age in the same above query?
  Is that possible?
  Can we write like this</p>
  
  <pre><code>from Parent as a where a.parentId=? and a.childList.age&gt; 10
  </code></pre>
  
  <p>Logically this doen't look proper. Any help will be appreciated.</p>
  
  <p>Thanks</p>