0

I have an object Worker with a collection of objects Job :

public class Worker {

    private int id;
    private String mail;
    private Set<Job> job;
}

public class Job {

    private int id;
    private String name;
}

I would like to make a request to get the Worker a certain mail and contains in his collection certain jobs (by their id). How could I do that ?

public List<Worker> getListWorker (String mail, List<Integer> listJobId){
     //Some hibernate magic here
}

I have tried a lot a things but none actually worked (add multiple restrictions on jobs, with alias, with detachedCriteria...). Can someone help me on this ?

Dr.Linus
  • 77
  • 3
  • 8

1 Answers1

0

I have found a working solution. I post it in case for others :

String query = "from Worker where email = '"+email+"' ";

for(Job job : worker.getJob()){
    query+="and '"+job.getId()+"' member of job "; //job -> Set<job>
}  

entityManager.createQuery(query, Worker.class).getResultList();
Dr.Linus
  • 77
  • 3
  • 8