Search code examples
mysqlhibernatenamed-queryin-clause

Inverse clause IN Named Query Hibernate


I need to acomplish something like this:

@NamedQuery (
   name="getEmployees",
   query="select object(em) from Employee em
          where (
              :workingGroup in em.listOfWorkingGroup1 or
              :workingGroup in em.listOfWorkingGroup2
          )"
)

I could get this to work.

I have 2 lists in an entity called Employee that represent groups of work.

And I want to get all the employees that have one particular workingGroup in one of their 2 lists of workingGroups. (workingGroup is a class, and listOfWorkingGroup1 and listOfWorkingGroup1 are Lists of workingGroup)

How could I manage to accomplish this?


Solution

  • Try with MEMBER OF

    select object(em) from Employee em where :workingGroup member of em.listOfWorkingGroup1 or :workingGroup member of em.listOfWorkingGroup2