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 我心依舊 閱讀(6599) 評論(1)  編輯  收藏

          FeedBack:
          # re: Hibernate 解決SQL count(*)的問題.
          2008-10-13 11:03 | 月影銷魂
          請問org.hibernate.SessionFactory sessionFactory 可以在這個函數體內申明嗎?如果不可以的話,那調用這個函數的Action是從哪獲取的sessionFactory ?  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 贺州市| 正宁县| 瓦房店市| 新郑市| 乌鲁木齐县| 六盘水市| 奉新县| 泰来县| 保康县| 忻州市| 韩城市| 洪湖市| 霞浦县| 嵩明县| 凭祥市| 安丘市| 达州市| 遂昌县| 平远县| 吕梁市| 灵宝市| 南部县| 星座| 德清县| 大新县| 康定县| 乐山市| 会泽县| 金堂县| 红原县| 成都市| 星子县| 崇明县| 伊春市| 正定县| 永州市| 罗山县| 新晃| 肥东县| 罗甸县| 徐汇区|