天空是藍色的

          做好軟件為中國 #gcc -c helloworld.c -o helloworld.o //編譯目標文件 #gcc helloworld.o -o helloworld //編譯成可執行exe #helloworld //運行exe
          數據加載中……
          修正一下Hibernate取count(*)的方法
              public int getCount(String emailGroupId, String emailBatchId)
                      
          throws HibernateException {

                  Session session 
          = HibernateUtil.currentSession();
                  Transaction tx 
          = session.beginTransaction();

                  String hql 
          = "select count(*) from EmailSendInfo where email_group_id = :emailGroupId and batch_id = :batchId";
                  Query query 
          = session.createQuery(hql);

                  query.setString(
          "emailGroupId", emailGroupId);
                  query.setString(
          "batchId", emailBatchId);
                  
          /*
                   * for (Iterator it = query.iterate(); it.hasNext();) { return
                   * ((Integer) it.next()).intValue(); }
                   
          */

                  
          try {
                      
          return ((Integer) query.iterate().next()).intValue();
                  }
           catch (Exception e) {
                      
          throw new HibernateException("");
                  }
           finally {
                      tx.commit();
                      HibernateUtil.closeSession();
                  }

              }

          posted on 2005-12-22 14:20 bluesky 閱讀(3383) 評論(3)  編輯  收藏 所屬分類: 工作總結

          評論

          # re: 修正一下Hibernate取count(*)的方法 2007-01-11 11:18 漂泊

          很好,謝謝,找了半天了!
          終于可以了
            回復  更多評論    

          # re: 修正一下Hibernate取count(*)的方法 2007-09-14 14:32 XT

          為什么我這樣寫,它卻總是報
          return ((Integer) query.iterate().next()).intValue();
          這句話類型轉換錯誤呢?
            回復  更多評論    

          # re: 修正一下Hibernate取count(*)的方法[未登錄] 2007-09-18 22:33 bluesky

          是不是你的數量太大了,超過了Integer類型的范圍了,試下Long?
            回復  更多評論    
          主站蜘蛛池模板: 新疆| 惠来县| 乳山市| 林西县| 沭阳县| 虹口区| 巴楚县| 北宁市| 渭南市| 葫芦岛市| 澄迈县| 屏山县| 铁力市| 江津市| 高阳县| 大安市| 霍山县| 宾川县| 琼中| 宁都县| 雅江县| 车致| 黄山市| 聂荣县| 财经| 商水县| 顺义区| 彭州市| 漳浦县| 巴林右旗| 文山县| 庄河市| 镇坪县| 茂名市| 准格尔旗| 邵阳市| 石柱| 山阴县| 蓬安县| 阿合奇县| 射洪县|