title: Hibernate : Create Filter on the nested Child of a nested Child
body: <p>hy,</p>
  
  <p>i got a problem with a type of query a bit complicated. To go straigh this is the SQL query i want to get :</p>
  
  <pre><code>select * from Parent parent
  left join fetch parent.child child
  left joint fetch child.grandchild grandchild with age &lt; 18;
  </code></pre>
  
  <p>The with clause is forbidden because of the fetch.</p>
  
  <p>So i got to use filters. But I didn't find the way to apply the filter on Grandchild I think this is because the @Filter or the @FilterDef aren't in the right class.</p>
  
  <p>For instant I declare the Filter (@FilterDef) in the Grandchild class, and I put the
  @Filter(name="age", condition = "age &lt; :age_param) just before the declaration
  of the Collection attribute in the Child class.
  The classes are like this :</p>
  
  <pre><code>public class Parent {
      @OneToOne(fetch = FetchType.LAZY,mappedBy="parent")
      private Collection&lt;Child&gt; children;
  }
  
  public class Child {
         private Parent parent;
  
          @Filter(name="age", condition = "age &lt; :age_param")
          @OneToMany(fetch = FetchType.LAZY,mappedBy="child")
          private Collection&lt;GrandChild&gt; grandchildren;
      }
  
  @FilterDef(name="majority",
             parameters={@ParamDef(name="age",type="int")}
               )
  public class GrandChild {
         private Child child;
         private int age;
      }
  </code></pre>
  
  <p>Then I do :</p>
  
  <pre><code>filter = session.enableFiler("majority");
  filter.setParameter("age_param",18);
  
  session.createQuery("select * from Parent parent
      left join fetch parent.child child
      left joint fetch child.grandchild")
  .list();
  </code></pre>
  
  <p>But there is no condition on the join whith grandchild.</p>
  
  <p>Is there a way to obtain this query ? am I doing something wrong ?</p>
  
  <p>Thanks for help</p>