我的表为:testtable
字段为:id int not,name decimal(10,2);
插入的测试数据为:
1,10.2
SQLQuery query = con.createSQLQuery("select * from testtable");
List products = query.list();
报错如下:
2010-5-20 15:18:17 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.ArithmeticException: Rounding necessary
at java.math.BigDecimal.divide(BigDecimal.java:1346)
at java.math.BigDecimal.setScale(BigDecimal.java:2310)
at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:35)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at org.chinaecce.b2b.service.impl.b2bQ.ProductListService.editQueryProduct(ProductListService.java:320)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
字段为:id int not,name decimal(10,2);
插入的测试数据为:
1,10.2
SQLQuery query = con.createSQLQuery("select * from testtable");
List products = query.list();
报错如下:
2010-5-20 15:18:17 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.ArithmeticException: Rounding necessary
at java.math.BigDecimal.divide(BigDecimal.java:1346)
at java.math.BigDecimal.setScale(BigDecimal.java:2310)
at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:35)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at org.chinaecce.b2b.service.impl.b2bQ.ProductListService.editQueryProduct(ProductListService.java:320)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
hql语句应该 (from POJO)
这个问题我也不知道怎么解决。
List products = query.list();
改成这样你试下
这个异常应该是decimal 类型转换的时候发生的
如果继承了
HibernateDaoSupportQuery query = super.getSession().CreatSqlQuery("select * from tablename");
--tablename是表名
List list = query.list();
你把数据库表中的name字段改成number类型,别用decimal(10,2)这个类型就ok
java.lang.ArithmeticException: Rounding necessary
at java.math.BigDecimal.divide(BigDecimal.java:1346)
lz你要仔细看异常,ArithmeticException去javaseapi查下这个异常吧
理解的意思是必须精确,所有要不你斟酌一下第二个参数,要不换类型
* sql.append(" select wit.idCard,
wit.personName,
ff.incomeYear,
ff.incomeMonth,
isnull(wit.allWage,0) as money "+
"from FinanceFlow ff , WageInfoTable wit "+
* " where ff.ffId = wit.ffId and not EXISTS ( select 1 from busi_people_money bpm where wit.idCard = bpm.idcard and "+
* " ff.incomeYear = bpm.money_Year and ff.incomeMonth = bpm.money_Month )");
*
*执行之:
* this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(sql.toString()).
* addScalar("idCard",Hibernate.STRING).
* addScalar("personName",Hibernate.STRING).
* addScalar("incomeYear",Hibernate.STRING).
* addScalar("incomeMonth",Hibernate.STRING).
* addScalar("money",Hibernate.FLOAT).list();
*
*
*****参考《Hibernate参考文档》。
*/ 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yuhua3272004/archive/2008/11/05/3228235.aspx---------------------------------------------------
可能真的跟你的数据类型转换有关
2010-5-20 15:18:17 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.ArithmeticException: Rounding necessary看这个异常就知道,和程序没有任何关系,
ArithmeticException看这意思,可能和数据类型转换有关。
session.clear();
String sql="select t.userid,t.username,t.pwd from user_tb t";
SQLQuery q = session.createSQLQuery(sql);
List l = q.list();
for(int i=0;i<q.list().size();i++){
System.out.println("****"+q.list().toString());
}
可以查询到你的sql语句的list对象
可以根据你的q.list().size()个数得到q.list().toString()的多个对象。
至于将查询到结果如何封闭成你要的POJO类,你自己得想办法解决。
Session session = HibernateSessionFactory.getSession();
session.clear();
String sql="select t.userid,t.username,t.pwd from user_tb t";
SQLQuery q = session.createSQLQuery(sql);
List l = q.list();
for(int i=0;i<q.list().size();i++){
System.out.println("****"+q.list().get(i));
}
可以查询到你的sql语句的list对象
可以根据你的q.list().size()个数得到q.list().toString()的多个对象。
至于将查询到结果如何封闭成你要的POJO类,你自己得想办法解决。这个例子测试通过,输出如下:
****[Ljava.lang.Object;@e60c4
****[Ljava.lang.Object;@9fa239