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

来源:互联网 发布:网络电话卡代理 编辑:程序博客网 时间:2024/05/29 11:24

关于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;
 
    }

计算总金额

原创粉丝点击