您的位置:首页 > 其它

Hibernate关于聚合函数的一些用法

2008-10-27 22:24 417 查看
关于hibernate中聚合函数的用法

1. public int countDetails() throws Exception {
// TODO Auto-generated method stub
Transaction trans = null;
trans = HibernateSessionFactory.getSession().beginTransaction();
int m =(Integer)HibernateSessionFactory.getSession().createQuery(
"select count(*) from Details").list().get(0);
trans.commit();
HibernateSessionFactory.closeSession();
return m;
}

返回数据总行数
2.public double countDetailsMoney() throws Exception {
Transaction trans = null;
trans = HibernateSessionFactory.getSession().beginTransaction();
Double m =(Double)HibernateSessionFactory.getSession().createQuery(
"select sum(money) from Details").list().get(0);
trans.commit();
HibernateSessionFactory.closeSession();
return m;

}

计算总金额
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: