I have @ManyToMany or @OneToMany associations on entity and I'm considering what will be the better use case:
using iterate for each object in objects and do criteriaBuilder.isMember(object, collection)
using root.join(collection) and than joinedRoot.in(objects)
Here code example:
List<Predicate> orPredicates = new ArrayList<>();
for(Industry industry : industries) {
orPredicates.add( criteriaBuilder.isMember(industry, provider.get(Provider_.industries)) );
}
predicates.add( criteriaBuilder.or(orPredicates.toArray(new Predicate[] { })) );
and the second possible solution
Join<Provider, Industry> industryRoot = provider.join(Provider_.industries)
industryRoot.in(industries);
// here i need also to add .distinct(true) on select
I consider whether .isMember() function is making dome join with associated entity through collection attribute?