title: JPA CriteriaBuilder - How to use "IN" comparison operator
body: <p>Can you please help me how to convert the following codes to using "in" operator of criteria builder?
  I need to filter by using list/array of usernames using "in".</p>
  
  <p><em>I also tried to search using JPA CriteriaBuilder - "in" method but cannot find good result.
  So I would really appreciate also if you can give me reference URLs for this topic. Thanks.</em></p>
  
  <p>Here is my codes:</p>
  
  <pre><code>//usersList is a list of User that I need to put inside IN operator 
  
  CriteriaBuilder builder = getJpaTemplate().getEntityManagerFactory().getCriteriaBuilder();
  CriteriaQuery&lt;ScheduleRequest&gt; criteria = builder.createQuery(ScheduleRequest.class);
  
  Root&lt;ScheduleRequest&gt; scheduleRequest = criteria.from(ScheduleRequest.class);
  criteria = criteria.select(scheduleRequest);
  
  List&lt;Predicate&gt; params = new ArrayList&lt;Predicate&gt;();
  
  List&lt;ParameterExpression&lt;String&gt;&gt; usersIdsParamList = new ArrayList&lt;ParameterExpression&lt;String&gt;&gt;();
  
  for (int i = 0; i &lt; usersList.size(); i++) {
  ParameterExpression&lt;String&gt; usersIdsParam = builder.parameter(String.class);
  params.add(builder.equal(scheduleRequest.get("createdBy"), usersIdsParam) );
  usersIdsParamList.add(usersIdsParam);
  }
  
  criteria = criteria.where(params.toArray(new Predicate[0]));
  
  TypedQuery&lt;ScheduleRequest&gt; query = getJpaTemplate().getEntityManagerFactory().createEntityManager().createQuery(criteria);
  
  for (int i = 0; i &lt; usersList.size(); i++) {
  query.setParameter(usersIdsParamList.get(i), usersList.get(i).getUsername());
  }
  
  List&lt;ScheduleRequest&gt; scheduleRequestList = query.getResultList();
  </code></pre>
  
  <p>The internal Query String is converted to below, so I don't get the records created by the two users, because it is using "AND".</p>
  
  <pre><code>select generatedAlias0 from ScheduleRequest as generatedAlias0 where ( generatedAlias0.createdBy=:param0 ) and ( generatedAlias0.createdBy=:param1 ) order by generatedAlias0.trackingId asc 
  </code></pre>