3

I am using JPA CriteriaBuilder api for generating queries, i have following set of beans:

  • Artist(contains the artist data like name, gender, address etc)
  • Role (contains Roles played by an artist like role id, role type, role description etc)

An artist can play different roles so it's a one-to-many relationship b/w Artist & Role entities. I want to write a query using criteriabuilder to fetch all artists who have not played the role of "HERO":

I found that criteriabuilder api provides the functions to handle collections, such as:

<E,C extends Collection<E>> Predicate isNotMember(Expression<E> elem,
                                              Expression<C> collection)

However, the examples I have found on internet for these functions are mostly using collection of string. As one given on this site (http://www.objectdb.com/java/jpa/query/jpql/collection) checks that languages collection doesn't contain French:

Predicate m4 = cb.isNotMember("French", languages);

How can I use the same function "isNotMember" with an Entity to fetch all artists that do not have a role with roleType as HERO?

suraj bahl
  • 2,864
  • 6
  • 31
  • 42

0 Answers0