I have done my fair amount of research and finally decided to ask this.
I have two classes like this:
Employee
-emp_id
-name
-dep_id
Department
-dep_id
-name
I'm using this code to query by example:
List<Employee> find = null;
Example example = Example.create(criteria)
.excludeZeroes()
.ignoreCase();
find = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(Employee.class)
.add(example)
.list() ;
return find;
The criteria object is an instance of Employee and I want to retrieve all employees with a given department name.
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"
It works correctly when the example has parent properties set but it does not filter on children properties.
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.
Any comments on this?