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