code: @Transactional
      public int findPropertyCount(E entity, SearchParameters sp, List<Attribute<?, ?>> attributes) {
          if (sp.hasNamedQuery()) {
              return byNamedQueryUtil.numberByNamedQuery(sp).intValue();
          }
          CriteriaBuilder builder = entityManager.getCriteriaBuilder();
          CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
          Root<E> root = criteriaQuery.from(type);
          Path<?> path = jpaUtil.getPath(root, attributes);
  
          if (sp.getDistinct()) {
              criteriaQuery = criteriaQuery.select(builder.countDistinct(path));
          } else {
              criteriaQuery = criteriaQuery.select(builder.count(path));
          }
  
          // predicate
          Predicate predicate = getPredicate(criteriaQuery, root, builder, entity, sp);
          if (predicate != null) {
              criteriaQuery = criteriaQuery.where(predicate);
          }
  
          // construct order by to fetch or joins if needed
          orderByUtil.buildJpaOrders(sp.getOrders(), root, builder, sp);
  
          TypedQuery<Long> typedQuery = entityManager.createQuery(criteriaQuery);
  
          applyCacheHints(typedQuery, sp);
          return typedQuery.getSingleResult().intValue();
      }
docs: Count the number of E instances.
  
  @param entity     a sample entity whose non-null properties may be used as search hint
  @param sp         carries additional search information
  @param attributes the list of attributes to the property
  @return the number of entities matching the search.