天空是藍(lán)色的

          做好軟件為中國(guó) #gcc -c helloworld.c -o helloworld.o //編譯目標(biāo)文件 #gcc helloworld.o -o helloworld //編譯成可執(zhí)行exe #helloworld //運(yùn)行exe
          數(shù)據(jù)加載中……
          修正一下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 閱讀(3377) 評(píng)論(3)  編輯  收藏 所屬分類(lèi): 工作總結(jié)

          評(píng)論

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

          很好,謝謝,找了半天了!
          終于可以了

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

          為什么我這樣寫(xiě),它卻總是報(bào)
          return ((Integer) query.iterate().next()).intValue();
          這句話(huà)類(lèi)型轉(zhuǎn)換錯(cuò)誤呢?

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

          是不是你的數(shù)量太大了,超過(guò)了Integer類(lèi)型的范圍了,試下Long?
          主站蜘蛛池模板: 烟台市| 霍城县| 双峰县| 吴江市| 莱西市| 满洲里市| 微博| 青阳县| 龙陵县| 桃园县| 全椒县| 宁乡县| 麻阳| 同心县| 房产| 铁岭市| 深州市| 天镇县| 独山县| 都兰县| 拉萨市| 新密市| 天门市| 雅江县| 家居| 九龙城区| 宜川县| 台前县| 科尔| 枞阳县| 民乐县| 通山县| 青冈县| 延长县| 抚松县| 武平县| 镇雄县| 武安市| 荆门市| 宾川县| 榕江县|