在执行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有关系?

解决方案 »

  1.   

    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 );
    }
    }
      

  2.   

    num字段数据库类型跟pojo类型不一致
      

  3.   

    select sum(t.num) from t_kucun t试试这句可以不.感脚num是数据库函数
      

  4.   

    t_kucunt应该是表名吧,感觉你写的是原生sql,改成createSqlQuery()试试