private String hql = "select sum(TOTAL_TICKETS) from VoteTeacher";
public long getTeacherListMaxSize(final String hql) {
long size = 0;
try {
size = (Long) this.getHibernateTemplate().execute(
new HibernateCallback() { public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
Long size = (Long) query.list().get(0);
return size; }
});
} catch (Exception e) {
}
return size;
}
这样查询,返回的结果总是为0!
但是hql语句改为:private String hql = "select count(TOTAL_TICKETS) from VoteTeacher";
可以返回记录的总数不为空!
public long getTeacherListMaxSize(final String hql) {
long size = 0;
try {
size = (Long) this.getHibernateTemplate().execute(
new HibernateCallback() { public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
Long size = (Long) query.list().get(0);
return size; }
});
} catch (Exception e) {
}
return size;
}
这样查询,返回的结果总是为0!
但是hql语句改为:private String hql = "select count(TOTAL_TICKETS) from VoteTeacher";
可以返回记录的总数不为空!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货