I am using Java8 and JPA2.
I would like to add a predicate to a where clause.
I have the following code:
@Override
public List<Job> findById(String ids, Integer type) {
String[] args = ids.split(",");
Set<String> idSet = new HashSet<String>(Arrays.asList(args));
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Job> query = builder.createQuery(Job.class);
Root<Job> post = query.from(Job.class);
CriteriaQuery<Job> criteria = query.select(post);
criteria.where(post.get("id").in(idSet));
//criteria.where(post.get("type").in(type)); <=== how do I do an equals
TypedQuery<Job> typedQuery = entityManager.createQuery(query);
List<Job> results = typedQuery.getResultList();
return results;
}
As you can see, I use a criteria
object and have a where
clause that filters on "ids" in the id set.
I would like to add an addition filter to the where clause, but am not sure how to. I would like to add a clause where column "type" equals the value in the type
Integer object.
i.e.
where id in [...] and type = 1
Any advise appreciated.