How to write criteria builder api query for below given JPQL query?
I am using JPA 2.2.
SELECT *
FROM Employee e
WHERE e.Parent IN (\'John\',\'
You can also do this with Criteria API In clause as below:
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(Employee.class);
Root root = cq.from(Employee.class);
List parentList = Arrays.asList("John", "Raj");
In in = cb.in(root.get(Employee_parent));
parentList.forEach(p -> in.value(p));
return entityManager
.createQuery(cq.select(root)
.where(in).orderBy(cb.asc(root.get(Employee_.Parent)))
.getResultList();
Checkout my Github for this and almost all possible criteria examples.