1. 程式人生 > >hibernate查詢總記錄數

hibernate查詢總記錄數

except back hiberna tee long lec err exceptio tco

@Override
public Integer getCount() {
return getHibernateTemplate().execute(new HibernateCallback<Integer>(){

@Override
public Integer doInHibernate(Session session) throws HibernateException {
String hql="select count(*) from Customer";
Query query = session.createQuery(hql);
int i = ((Long) query.setCacheable(true).uniqueResult()).intValue();
return i;
}
});
}

hibernate查詢總記錄數