Does the JPQL avg aggregate function work with Integers?
Posted
by Kyle Renfro
on Stack Overflow
See other posts from Stack Overflow
or by Kyle Renfro
Published on 2010-05-07T20:06:46Z
Indexed on
2010/05/07
21:48 UTC
Read the original article
Hit count: 269
I have a JPA 2 Entity named Surgery. It has a member named transfusionUnits that is an Integer.
There are two entries in the database. Executing this JPQL statement:
Select s.transfusionUnits from Surgery s
produces the expected result:
2
3
The following statement produces the expected answer of 5:
Select sum(s.transfusionUnits) from Surgery s
I expect the answer of the following statement to be 2.5, but it returns 2.0 instead.
Select avg(s.transfusionUnits) from Surgery s
If I execute the statement on a different (Float) member, the result is correct. Any ideas on why this is happening? Do I need to do some sort of cast in JPQL? Is this even possible? Surely I am missing something trivial here.
© Stack Overflow or respective owner