码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate查询总的记录数

时间:2014-12-19 11:28:23      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   sp   on   数据   div   log   

1. 原生sql

String hql="select count(*) from product" ;//此处的product是数据库中的表名 
Query query=session.createSQLQuery(hql); 
List<BigInteger> list=query.list(); //此处胡一定要注意是Bignter类型的,傻了吧唧的试了好多(Long,Integer)都报错 
count = list.get(0).intValue();

 

2.hql语句

 String hql="select count(*) from Product";//此处的Product是对象
 Query query = session.createQuery(hql);
 count=((Long) query.setCacheable(true).uniqueResult()).intValue();//此处用Long类型进行转换

 

 

 

Hibernate查询总的记录数

标签:style   blog   io   color   sp   on   数据   div   log   

原文地址:http://www.cnblogs.com/yaoqj/p/4173270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!