HTTP Status 500 - java.lang.Long cannot be cast to java.lang.Integer
2015-07-26 11:07
639 查看
Hibernate HQL 语句查询时,有时候会遇到这个问题:java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
根据定位:找到出错的 代码位置
通过调用 allCount 方法,查询出,fw 信息的总数量。String hql1 = "select count(fw) from TblFwxx as fw where fw.tblUser.uid="+tbuser.getUid(); count = tbifw.allCount(hql1);
allCount(String hql) 方法为:
public Integer allCount(String hql){ Session session = HibernateUtil.getSession(); /*--------出错语句-------*/ Integer count = (Integer) session.createQuery(hql).uniqueResult(); session.close(); return count; }
出错语句是:
Integer count = (Integer) session.createQuery(hql).uniqueResult();
1、可以这样改:
Long count = (Long) session.createQuery(hql).uniqueResult(); session.close(); return count.intValue();
2、也可以这样改:
Number count = (Number) session.createQuery(hql).uniqueResult(); //因为 Number 是 Long 和 Integer 的父类 session.close(); return count.intValue();
相关文章推荐
- HTTP简单的解析协议
- sprintf和printf http://blog.sina.com.cn/s/blog_44f08a12010007pi.html
- lr函数--web_get_int_property(记录HTTP响应信息)
- 【试水CAS-4.0.3】第06节_CAS服务端配置HTTPS
- LINUX C获取文件大小 http://my.oschina.net/mavericsoung/blog/138769
- poj PIGS 网络流EK
- web中的HTTP协议
- TCP编程,Socket通讯
- http代理
- http压缩
- http缓存
- http协议详解
- 虚拟机下centos6的网络IP配置
- HTTP学习要点(一)
- 网络科技协会暑假第一周学习计划报告
- httpclient发送不带参数post数据
- 社交网络编程API之iOS系统自带分享
- 新博客,新起点!
- linux系统CPU,内存,磁盘,网络流量监控脚本
- linux系统CPU,内存,磁盘,网络流量监控脚本