title: Hibernate Example Criteria query: filtering by child properties
body: <p>I have done my fair amount of research and finally decided to ask this.</p>
  
  <p>I have two classes like this:</p>
  
  <pre><code>Employee
  -emp_id
  -name
  -dep_id
  
  Department
  -dep_id
  -name
  </code></pre>
  
  <p>I'm using this code to query by example:</p>
  
  <pre><code>List&lt;Employee&gt; find = null;
  Example example = Example.create(criteria)
          .excludeZeroes()
          .ignoreCase();
  find = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(Employee.class)
          .add(example)
          .list() ;
  return find;
  </code></pre>
  
  <p>The criteria object is an instance of Employee and I want to retrieve all employees with a given department name.</p>
  
  <p>The problem is that when I execute the code I get employees from all departments even when criteria has a property set like this:
     criteria.department.name = "IT"</p>
  
  <p>It works correctly when the example has parent properties set but it does not filter on children properties.</p>
  
  <p>From what I can see I have to create aliases to join child properties but that kind of defeats the purpose of the Example criteria.</p>
  
  <p>Any comments on this?</p>