隨筆-86  評論-33  文章-0  trackbacks-0
          Hibernate3.0對批量更新和批量刪除提供了支持,能夠直接執行批量更新或批量刪除語句,無需把被更新或刪除的對象先加載到內存中。以下是通過Hibernate3.0執行批量更新的程序代碼:
          Session session = sessionFactory.openSession(); 
          Transaction tx 
          = session.beginTransaction(); 
          String hqlUpdate 
          = "update Customer set name = :newName where name = :oldName"
          int updatedEntities = s.createQuery( hqlUpdate ) 
          .setString( 
          "newName", newName ) 
          .setString( 
          "oldName", oldName ) 
          .executeUpdate(); 
          tx.commit(); 
          session.close(); 
          以下是通過Hibernate3.0執行批量刪除的程序代碼:
          Session session = sessionFactory.openSession(); 
          Transaction tx 
          = session.beginTransaction(); 
          String hqlDelete 
          = "delete Customer where name = :oldName"
          int deletedEntities = s.createQuery( hqlDelete ) 
          .setString( 
          "oldName", oldName ) 
          .executeUpdate(); 
          tx.commit(); 
          session.close(); 

          posted on 2006-03-15 16:24 Derek.Guo 閱讀(1518) 評論(0)  編輯  收藏 所屬分類: Java
          MSN:envoydada@hotmail.com QQ:34935442
          主站蜘蛛池模板: 体育| 津南区| 濉溪县| 兰西县| 社会| 个旧市| 广饶县| 龙南县| 洪洞县| 长丰县| 东城区| 永年县| 乐平市| 星子县| 江永县| 开江县| 武隆县| 青州市| 开封县| 岑溪市| 瑞安市| 江源县| 新竹县| 揭阳市| 开封县| 祁连县| 马尔康县| 临沭县| 行唐县| 玉树县| 万载县| 紫阳县| 抚顺市| 天气| 阳信县| 金堂县| 田东县| 富川| 集安市| 渑池县| 唐海县|