Does the JPQL avg aggregate function work with Integers?
- by Kyle Renfro
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.