在spring-Hibernate示例中执行aggrigate查询时出现异常

时间:2015-09-05 11:41:23

标签: hibernate spring-mvc

   String SQL_QUERY ="select avg(RATING_NUMBER) From RatingModel where PRODUCT_FK='"+productId+"'";
       Query query = session.createQuery(SQL_QUERY);//<--exception
        List list = query.list();
        System.out.println("Average" + list.get(0)); 

例外

显示java.lang.NullPointerException     at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions $ AvgFunction.determineJdbcTypeCode(StandardAnsiSqlAggregationFunctions.java:98)     at org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions $ AvgFunction.render(StandardAnsiSqlAggregationFunctions.java:92)     在org.hibernate.hql.internal.ast.SqlGenerator.endFunctionTemplate(SqlGenerator.java:220)

我也这样做
但同样的例外发生

double avg =((Double)session.createQuery(SQL_QUERY).uniqueResult())。doubleValue();

0 个答案:

没有答案