How can I build a predicate filtering to where ALL tags in an array exist, joined to a record, using criteriaBuilder?


Here’s an example of the syntax I’m using for another condition (where ANY of the tags appear on the document via a FK).

predicates.add(root.join(Document_.tags).in({ pseudocode array of tags }));

I’m trying to come up with a similar predicate, but where the Document entity has ALL of the tags listed in the filter.


if all the tags listed in the filters are all the tags that exist you could try this


or, if the tags in the filter are a subset of all of the tags, try this one

    .map(tag -> criteriaBuilder.isMember(tag, root.get(Document_.tags)))

Answered By – tremendous7

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published