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\',\'
Not to break your head when you need to do this again using Criteria API - you can create a parent wrapper class for your Dao and put a hepler method there:
/**
* An SQL "WHERE IN" expression alternative.
*
* @param inList List to search in.
* @param pathToEntityField Path to a field in your entity object.
* @return A ready predicate-condition to paste into CriteriaQuery.where().
*/
@SuppressWarnings("unchecked")
private Predicate in(List> inList, Expression pathToEntityField) {
return pathToEntityField.in(inList);
}
Use WHERE IN then like:
query.where(**in**(myList, root.get(MyTypedEntity_.id)));