报错:java.lang.Long cannot be cast to java.lang.Integer
2014-05-09 18:32
561 查看
Long 无法转化成Integer类型.
这个异常 经常出现在hinbernate分页查询的时候.
原因:
这里在Hibernate2.0之前版本list.get(0)返回的是Integer类型.
但是在Hibernate3.0以后版本list.get(0)返回的是Long类型.
解决方法
public Integer getUsersCount() {
String hql = "select count(*) from Users";
List list = super.pageQuery(hql, null, null, null);
Number num = (Number) list.get(0);
return num.intValue();
}
注:java.lang.Number是Integer,Long的父类. //重点
这个异常 经常出现在hinbernate分页查询的时候.
原因:
这里在Hibernate2.0之前版本list.get(0)返回的是Integer类型.
但是在Hibernate3.0以后版本list.get(0)返回的是Long类型.
解决方法
public Integer getUsersCount() {
String hql = "select count(*) from Users";
List list = super.pageQuery(hql, null, null, null);
Number num = (Number) list.get(0);
return num.intValue();
}
注:java.lang.Number是Integer,Long的父类. //重点
相关文章推荐
- java.math.BigInteger cannot be cast to java.lang.Long异常
- java.lang.Long cannot be cast to java.lang.Integer解决办法
- detachedCriteria: java.lang.integer cannot be cast to Long
- hibernate :java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
- error:java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
- java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
- java.lang.Integer cannot be cast to java.lang.Long异常处理
- HTTP Status 500 - java.lang.Long cannot be cast to java.lang.Integer
- java.lang.Long cannot be cast to java.lang.Integer解决方案
- java.math.BigInteger cannot be cast to java.lang.Long
- java.math.BigInteger cannot be cast to java.lang.Long
- java.lang.Long cannot be cast to java.lang.Integer
- 十三、java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
- java.lang.Long cannot be cast to java.lang.Integer解决办法
- java.lang.Long cannot be cast to java.lang.Integer!
- java.math.BigInteger cannot be cast to java.lang.Long
- MyBatis 插入MySQL数据库返回主键异常 java.lang.Integer cannot be cast to java.lang.Long
- java.lang.Long cannot be cast to java.lang.Integer的问题(Hibernate)
- java.lang.Long cannot be cast to java.lang.Integer
- hibernate :java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer