// 用于hibernate 2.x
protected String getCountSql(String originalHql, net.sf.hibernate.SessionFactory sessionFactory) throws Exception {
QueryTranslator translator = new QueryTranslator(originalHql);
translator.compile((net.sf.hibernate.engine.SessionFactoryImplementor)sessionFactory, Collections.EMPTY_MAP, false);
return "select count(*) from (" + translator.getSQLString() + ") tmp_count_t";
}
// 用于hibernate 3.x
protected String getCountSql(String originalHql, org.hibernate.SessionFactory sessionFactory) throws Exception {
QueryTranslatorImpl queryTranslator = new QueryTranslatorImpl(originalHql, originalHql,
Collections.EMPTY_MAP, (org.hibernate.engine.SessionFactoryImplementor)sessionFactory);
queryTranslator.compile(Collections.EMPTY_MAP, false);
return "select count(*) from (" + queryTranslator.getSQLString() + ") tmp_count_t";
}
String strHQL = "Select count(*) From tb_po";
Long count = (Long)session.createQuery(strHQL).uniqueResult();
posted on 2007-06-05 11:28
我心依旧 阅读(6565)
评论(1) 编辑 收藏