I would expect it to return Long
, because that is consistent with JPQL. In JPA 2.0 specification SUM function is described as follows:
SUM returns Long when applied to state fields of integral types (other than BigInteger); Double when applied to state fields of floating point types; BigInteger when applied to state fields of type BigInteger; and BigDecimal when applied to state fields of type BigDecimal.
Also Hibernate seems to works that way and return type is Long
.
If Long
is preferred, return type can be affected also with EclipseLink. That can be done via CriteriaBuilder.sumAsLong:
final Expression<Long> sumActiveExp = cb.sumAsLong(activeExp);