title: getting sum of a column using CriteriaBuilder
body: <p>I am trying to get a Sum of amount using criteria (Criteria Builder and CriteriaQuery)</p>
  
  <p>But I am getting a error when I am writing the code;
  Here is my code</p>
  
  <pre><code>    public Long findAmountByCriteria(OrderCriteria orderCriteria) {
  
    final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    final CriteriaQuery&lt;BigDecimal&gt; query = criteriaBuilder.createQuery(BigDecimal.class);
    Root&lt;Order&gt; root = query.from(Order.class);
  
    query.select(criteriaBuilder.sum(root.get("amount")))
    .where(buildPredicateForOrderResponseCriteria(criteriaBuilder, orderCriteria, root));
  
    final TypedQuery&lt;BigDecimal&gt; typedQuery = entityManager.createQuery(query);
    return typedQuery.getSingleResult().longValue();
  }
  </code></pre>
  
  <p>Amount is in a BigDecimal value.</p>
  
  <p>in select mehtod it says,</p>
  
  <pre><code>The method select(Selection&lt;? extends BigDecimal&gt;) in the type CriteriaQuery&lt;BigDecimal&gt; is not applicable for the arguments (Expression&lt;Object&gt;)
  </code></pre>
  
  <p>in sum method</p>
  
  <pre><code>Bound mismatch: The generic method sum(Expression&lt;N&gt;) of type CriteriaBuilder is not applicable for the arguments (Path&lt;Object&gt;). The inferred type Object is not a valid substitute for the bounded parameter &lt;N extends Number&gt;
  </code></pre>
  
  <p>How can I fix this problem.</p>