'Java Predicates In clause: illegal argument exception?

I am trying to create a java predicate that gets all entities that match a certain Id:

 public Predicate createPredicate(List<Integer> personIds){
 
 Predicate newPredicate = null;
 if(!personIds.isEmpty()){
      CriteriaBuilder.In<Integer> inClause = builder.in(from.get(PERSON_ID));
      for (Integer personId : personIds) {
        inClause.value(personId);
      }
      newPredicate = builder.in(inClause);
    }

    return newPredicate;
  }

However when I try to get the count results from this (see below) I get an illegal argument exception.

What is the issue?

private Long getResultsCount(Predicate predicate) throws ATSException {

    CriteriaBuilder countBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> countQuery = countBuilder.createQuery(Long.class);
    Root<Person> countFrom = countQuery.from(Person.class);
    countQuery = countQuery.select(countBuilder.count(countFrom));
   
    countQuery.where(predicate);

    return entityManager.createQuery(countQuery).getSingleResult();
  }

Error:

   java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: in near line 1, column 177 [select count(generatedAlias0) from com.model.Person as generatedAlias0 where ( generatedAlias0.status=:param0 ) and ( ( generatedAlias0.personId in () in () ) and ( ( generatedAlias0.personId in () in () ) and ( generatedAlias0.personId in () in () ) ) )]\r\n\tat org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1374)\r\n\tat 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source