2008年3月6日星期四

Hibernate 3.2 移植: SQL函数返回类型改变

In alignment with the JPA specification the count, sum and avg function now defaults to return types as specified by the specification. This can result in ClassCastException at runtime if you used aggregation in HQL queries.

Actually the spec says

The Java type that is contained in the result of a query using an aggregate function is as follows[33]:
COUNT returns Long.
MAX, MIN return the type of the state-field to which they are applied.
AVG returns Double.
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.

http://www.hibernate.org/250.html#A44
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1538

没有评论: