title: can I use Hibernate filtering annotations to filter an entity by child collection content?
body: <p>I have an entity ParentEntity defined as</p>
  
  <pre><code>public class ParentEntity
  {
     private long id;
     private List&lt;ChildEntity&gt; children;
  
     @OneToMany(mappedBy = "parent")
     public List&lt;ChildEntity&gt; getChildren()
     {
         return children;
     }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class ChildEntity
  {
     private ParentEntity parent;
     private String code; 
     ...
  }
  </code></pre>
  
  <p>I understand that using the annotation @FilterJoinTable I can filter parents have a child with a specific code, defined as filter parameter, but
  I'm trying to figure how to filter by annotations the parents that have no childern or a child with code as the parameter defined. </p>
  
  <p>Something like SQL:</p>
  
  <pre><code>select * from ParentEntity p left join ChildEntity c 
                  on p.id=c.parent_id
  where p.id in (select p.id from ParentEntity p join ChildEntity c 
                  on p.id=c.parent_id where c.code=:code) 
  OR p.id  not in ( select parent_id from ChildEntity )
  </code></pre>
  
  <p>or HQL:</p>
  
  <pre><code>select p from ParentEntity p join fetch p.childen c 
  where p.id in (select p.id from ParentEntity p join p.childen c where c.code=:code) 
  OR p.id  not in ( select c.parent.id from ChildEntity c )
  </code></pre>
  
  <p>This because I've a lot of classes with <code>Parent</code> or <code>List&lt;Parent&gt;</code> as property and each one retreives the <code>ChildEntity</code> too, always with the same condition above, so I wouldn't rewrite the same condition on all the queries.</p>
  
  <p>Have you any idea?</p>
  
  <p>Thanks</p>