Hi, i'm using Hibernate 3.5.1 as JPA2 implementation. I'm trying to create a query tha uses AVG function. My problem is: i have a BigDecimal attribute but when i use avg(value), it returns a Double and a exceptin is throwed. Here is my code:
Code:
public BigDecimal calculaTotalMovimentado(Conta conta, TipoMovimentacao tipo) {
String jpql = "select avg(valor) from Movimentacao where conta=:pConta and"
+ " tipo=:pTipo";
TypedQuery<BigDecimal> query = this.em.createQuery(jpql,BigDecimal.class);
query.setParameter("pConta", conta);
query.setParameter("pTipo", tipo);
return query.getSingleResult();
}
When i try to run a get this exception:
Code:
Exception in thread "main" java.lang.IllegalArgumentException: Type specified for TypedQuery [java.math.BigDecimal] is incompatible with query return type [class java.lang.Double]
The "valor" attribute is a BigDecimal. Is this a bug or my mistake ?
Thanks,
Alberto