隨筆-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
          主站蜘蛛池模板: 房产| 千阳县| 镇江市| 东阿县| 民和| 松原市| 邳州市| 应城市| 红原县| 横峰县| 九江县| 友谊县| 彭阳县| 合山市| 郯城县| 班玛县| 呼伦贝尔市| 安阳市| 教育| 常宁市| 嘉峪关市| 海林市| 婺源县| 开江县| 西昌市| 麻江县| 琼结县| 都兰县| 错那县| 开江县| 巩义市| 浠水县| 丹东市| 丰台区| 荣昌县| 资源县| 乌兰浩特市| 慈溪市| 论坛| 大渡口区| 莱芜市|