title: JPA count(*) using CriteriaBuilder
body: <p>I have a question about CriteriaBuilder API. I am new in JPA, I would like to create a <strong>count(*)</strong> thought a CriteriaBuilder. The count that I need to create  needs to use  the same parameters that I using in this dynamic query, that I created</p>
  <p>I have this service to create a dynamic query but I do not have an idea to how to create a <strong>count(*)</strong> using the same parameters</p>
  <pre><code>package com.sanmina.rohsappapirest.model.services.imp;
  
  
  /**
   * @author edgar_conrado on 07/07/2020
   *
   */
  @Service
  public class ItemFilterServiceImp implements IItemFilterService {
  
      @Autowired
      private IItemFilterDao itemFilterDao;
  
      
      /**
       * This function to get the items providing parameters
       * 
       * @param manufacturers     Array with the manufacturer to found
       * @param mpnReachs         Array with the mpnReachs to found
       *  
       * @return List with the items
       */
      @Override
      @Transactional(readOnly = true)
      public List&lt;ItemFilter&gt; findByInManufacturer(String[] manufacturers, String[] mpnReachs) {      
          return itemFilterDao.findAll(new Specification&lt;ItemFilter&gt;() {
  
              /**
               * 
               */
              private static final long serialVersionUID = 1L;
  
              @Override
              public Predicate toPredicate(Root&lt;ItemFilter&gt; root, CriteriaQuery&lt;?&gt; query, CriteriaBuilder criteriaBuilder) {          
                  List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
                  
                  // Criteria for Manufacturer
                  if (manufacturers!=null) {                  
                      // Convert the array in a List
                      List&lt;String&gt; manufacturerList = new ArrayList&lt;String&gt;();
                      for (String l : manufacturers) {
                          manufacturerList.add(l);
                      }
  
                      //Create the query
                      In&lt;String&gt; predicate = criteriaBuilder.in(root.get(&quot;manufacturer&quot;));                                        
                      manufacturerList.forEach(t -&gt; predicate.value(t));  
  
                      predicates.add(predicate);
                      //predicates.add(criteriaBuilder.and(criteriaBuilder.in(root.get(&quot;manufacturer&quot;))));                    
                  }
                  
                  // Criteria for Reach
                  if (mpnReachs!=null) {                  
                      // Convert the array in a List
                      List&lt;String&gt; reachList = new ArrayList&lt;String&gt;();
                      for (String l : mpnReachs) {
                          reachList.add(l);
                      }
  
                      //Create the query
                      In&lt;String&gt; predicate = criteriaBuilder.in(root.get(&quot;mpnReach&quot;));                                        
                      reachList.forEach(t -&gt; predicate.value(t));                 
                      predicates.add(predicate);                  
                  }
                                          
                  return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
              }
  
          });
      }
          
  }
  </code></pre>
  <p>Any suggestion?</p>