Reputation: 297
My question is based on this other question: Selecting where an entity contains a list thats a subset of another list
But what I want to do is this:
I am writing a JPQL query and i have the following scenario. I have a Question entity which contains a list of Tags. I would like to select all Questions that do not contains any given tag in a List. How do i do this with JPA?
I would like to do something like SELECT x FROM Question x WHERE x.tags 'do not contains any' :tags
I tried to use 'NOT IN', but it not work. In this case, it's returned all Question with at least on tag not in the 'tags' list. I want to return only the Question with all the tags not in the 'tags' list.
Any suggestions?
Upvotes: 2
Views: 2714
Reputation: 21155
Try a sub select that finds the employee with a project in the list, then use not exists in the main query. Something like
SELECT x FROM Question x WHERE not exists( select tag from x.tags tag where tag in :tags )
Upvotes: 1