Java in Action
My goal 架构设计师,为精通SSH而奋斗...
posts - 68,comments - 228,trackbacks - 0

// 用于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 我心依旧 阅读(2042) 评论(0)  编辑  收藏

标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-06-05 11:44 编辑过
 
成果网帮您增加网站收入
 
相关链接:
网站导航: