2.10.2.8.7. JPQL Numeric Expressions in the SELECT Clause

The type of a numeric expression in the query result is determined as follows:

An operand that corresponds to a persistent state-field is of the same type as that persistent state-field.

An operand that corresponds to one of arithmetic functions described in JPQL Arithmetic Functions is of the type defined by JPQL Arithmetic Functions.

An operand that corresponds to one of an aggregate functions described in JPQL Aggregate Functions is of the type defined by JPQL Aggregate Functions.

The result of a case expression, coalesce expression, nullif expression, or arithmetic expression (+, -, *, /) is determined by applying the following rule to its operands.

  • If there is an operand of type Double or double, the result of the operation is of type Double;

  • otherwise, if there is an operand of type Float or float, the result of the operation is of type Float;

  • otherwise, if there is an operand of type BigDecimal, the result of the operation is of type Big- Decimal;

  • otherwise, if there is an operand of type BigInteger, the result of the operation is of type BigInteger;

  • otherwise, if there is an operand of type Long or long, the result of the operation is of type Long;

  • otherwise, if there is an operand of integral type, the result of the operation is of type Integer.