隨筆-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 閱讀(1516) 評論(0)  編輯  收藏 所屬分類: Java
          MSN:envoydada@hotmail.com QQ:34935442
          主站蜘蛛池模板: 页游| 蓬溪县| 安康市| 白水县| 博客| 诸暨市| 德化县| 颍上县| 六安市| 嘉荫县| 昆山市| 柯坪县| 孟村| 霞浦县| 民勤县| 恩施市| 红桥区| 新龙县| 苍南县| 水城县| 民和| 高要市| 沙湾县| 双辽市| 宁阳县| 安岳县| 富顺县| 德格县| 榆社县| 灵丘县| 漳平市| 辽阳市| 黄冈市| 阿拉善右旗| 北宁市| 教育| 安化县| 滕州市| 清苑县| 依安县| 富源县|