posts - 70,comments - 408,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 我心依旧 阅读(6514) 评论(1)  编辑  收藏

feedback:
# re: hibernate 解决sql count(*)的问题.
2008-10-13 11:03 |
请问org.hibernate.sessionfactory sessionfactory 可以在这个函数体内申明吗?如果不可以的话,那调用这个函数的action是从哪获取的sessionfactory ?  回复  
  

只有注册用户后才能发表评论。


网站导航:
              
 
网站地图