隨筆-86  評論-33  文章-0  trackbacks-0
          Hibernate3.0對批量更新和批量刪除提供了支持,能夠直接執(zhí)行批量更新或批量刪除語句,無需把被更新或刪除的對象先加載到內(nèi)存中。以下是通過Hibernate3.0執(zhí)行批量更新的程序代碼:
          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執(zhí)行批量刪除的程序代碼:
          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
          主站蜘蛛池模板: 汽车| 邛崃市| 武冈市| 开原市| 天门市| 合作市| 苏尼特右旗| 泾川县| 永济市| 浙江省| 千阳县| 太和县| 嘉义市| 苗栗市| 勃利县| 怀宁县| 西乌珠穆沁旗| 攀枝花市| 定西市| 略阳县| 荣昌县| 昆明市| 马山县| 永川市| 齐河县| 丰台区| 荔波县| 万州区| 吴桥县| 舞钢市| 大宁县| 定陶县| 拉萨市| 济南市| 金塔县| 迁西县| 阿尔山市| 温宿县| 宁安市| 三门县| 隆回县|