I have these (simplified) entities:
@Entity public class Project { @ManyToOne private Type type; } @Entity public class Type { @ManyToOne private Category category; } @Entity public class Category { } No I want to query all projects belonging so to selected Types with a CriteriaQuery.
List<Type> types = ... List<Category> categories = ... CriteriaBuilder cB = em.getCriteriaBuilder(); CriteriaQuery<MeisProject> cQ = cB.createQuery(Project.class); Root<Project> project = cQ.from(Project.class); cQ.where(cB.isTrue(project.get("type").in(types))); cQ.select(project).distinct(true); return em.createQuery(cQ).getResultList(); This works fine, but how to I add the categories to this query? The category is a property of the type, I want to query all projects
- belonging to a list of types (working in the example)
- AND belonging to a type in a list of categories (the reason for this question)