在执行Query query = session.createQuery(hql);这句时提示出错
java.lang.NullPointerException at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$SumFunction.determineJdbcTypeCode(StandardAnsiSqlAggregationFunctions.java:145)后台输出hql语句是select sum(num) from t_kucun,之后就提示出错了
但是hql换成select sum(num*price) from t_kucun就不会出错
数据库中num和price都是float类型
后来我试了一下把hql改成select sum(num*1.0) from t_kucun就不会出错了为什么加个*1.0就没错误了,createQuery时跟int float有关系?
java.lang.NullPointerException at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions$SumFunction.determineJdbcTypeCode(StandardAnsiSqlAggregationFunctions.java:145)后台输出hql语句是select sum(num) from t_kucun,之后就提示出错了
但是hql换成select sum(num*price) from t_kucun就不会出错
数据库中num和price都是float类型
后来我试了一下把hql改成select sum(num*1.0) from t_kucun就不会出错了为什么加个*1.0就没错误了,createQuery时跟int float有关系?
protected final int determineJdbcTypeCode(Type type, Mapping mapping) throws QueryException {
try {
final int[] jdbcTypeCodes = type.sqlTypes( mapping );
if ( jdbcTypeCodes.length != 1 ) {
throw new QueryException( "multiple-column type in sum()" );
}
return jdbcTypeCodes[0];
}
catch ( MappingException me ) {
throw new QueryException( me );
}
}