-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Example queries for many to many relations?
PostPosted: Thu May 03, 2007 4:28 pm 
Newbie

Joined: Tue Nov 07, 2006 5:34 pm
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.