各位大哥,小弟初次使用hibernate抛出了如上异常不知道该如何处理,主要代码如下:
Session session = null;
try{
session = HibernateUtil.getSessionFactory().openSession();
List l = session.createSQLQuery("select count(*) from person").list();
int t = l.get(0).intValue();
System.out.println(t);
}catch(Exception e){
e.printStackTrace();
}finally{
session.close();
}
我想执行上面的语句来得到数据库中数据的条数,但是不知道有什么好的方法,所以就想用上面的代码试试,结果出现了这个异常,不知道各位有什么好的方法可以告诉小弟一声,谢谢!
提示很清楚
返回的count(*)这个数字是BigInteger, 不是Integer
用BigInteger替换代码中的Integer
一楼标准答案 想顶下 不够100积分、
List l = session.createSQLQuery("select count(*) from person").list();
这行代码有问题啦
修改成
[code="java"]
Session session = null;
try{
session = HibernateUtil.getSessionFactory().openSession();
List l = session.createSQLQuery("select count(*) from person").list();
int t = l.get(0).intValue();
System.out.println(t);
}catch(Exception e){
e.printStackTrace();
}finally{
session.close();
}
[/code]