Hibernate version:
3.2.3 GA
Mapping documents:
Code:
@Entity
public class Employee
{
@ManyToMany @OrderBy("priority desc")
private List<Task> tasks = new ArrayList<Task>(0);
}
@Entity
public class Task
{
@NotEmpty @Column(unique = true)
private String name;
@NotNull
private Integer priority;
@ManyToMany(mappedBy="tasks")
private List<Employee> employees= new ArrayList<Employee>(0);
}
With the given relation, I want to query for employees with particular taks. Suppose I have a multi select box with all available tasks. The user can select on or more tasks. The result is a List of Tasks. Now I want to return all employees, who work on
all of the selected taks.
The Example criteria unfortunatly ignores associations, so the following does not work:
Code:
Employee emp = new Employee();
emp.setTasks(selectedListOfTasks);
List results = session.createCriteria(Employee.class)
.add( Example.create(emp) )
.list();
However, nor was I able to come up with a working HQL query. Any help his highly appreciated!
Regards
Christian