2016-08-18 16 views
0

を使用して列の合計を取得します。 はここは私が基準(基準BuilderとCriteriaQuery)</p> <p>を使用量の合計を取得しようとしています。しかし、私はコードを書いていたとき、私はエラーを取得していますCriteriaBuilder

public Long findAmountByCriteria(OrderCriteria orderCriteria) { 

    final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); 
    final CriteriaQuery<BigDecimal> query = criteriaBuilder.createQuery(BigDecimal.class); 
    Root<Order> root = query.from(Order.class); 

    query.select(criteriaBuilder.sum(root.get("amount"))) 
    .where(buildPredicateForOrderResponseCriteria(criteriaBuilder, orderCriteria, root)); 

    final TypedQuery<BigDecimal> typedQuery = entityManager.createQuery(query); 
    return typedQuery.getSingleResult().longValue(); 
} 

金額がBigDecimal値である私のコードです。和法

Bound mismatch: The generic method sum(Expression<N>) of type CriteriaBuilder is not applicable for the arguments (Path<Object>). The inferred type Object is not a valid substitute for the bounded parameter <N extends Number> 

でそれが言う選択mehtodで

The method select(Selection<? extends BigDecimal>) in the type CriteriaQuery<BigDecimal> is not applicable for the arguments (Expression<Object>) 

は、どのように私はこの問題を解決することができます。代わりにあなたが

query.select(criteriaBuilder.sum(root.get("amount"))) 

をやっているの

答えて

1

この

query.select(criteriaBuilder.sum(root.<BigDecimal> get("amount"))) 
をやってみてください
関連する問題