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