王德森

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

今天在使用hibernate进行分页操作,在进行到使用hibernate查询总记录的时候,我的查询语句是这样的:

      Integer count = (Integer)session.createQuery("select count(*) from Topic").uniqueResult();

      return count;

这种情况总是报错:java.lang.Long cannot be cast to java.lang.Integer

原因是hibernate提供的查询导致的类型转换错误,改成下列语句便可以通过运行:

      long count = (Long)session.createQuery("select count(*) from Topic").uniqueResult();

      Integer res= new Integer(String.valueOf(count));

      return res;

程序错误解除。。。

posted on 2014-04-13 02:57  王德森  阅读(1317)  评论(0)    收藏  举报