JAVA | mysql | php | DELPHI | ORACLE | .NET | FLEX | HTML | C++ | LINUX
您所在的位置: 首页 > 我的资料

Hibernate3 批量更新/删除

来源:武汉999
浏览次数:0                             2010-02-25 00:00
我要评论(0)  |  复制链接  |     

Hibernate3 对批量更新和批量删除提供了支持,能够直接执行批量更新或批量删除语句,无需把被更新或删除的对象先加载到内存中。

以下是通过Hibernate3 执行批量更新的程序代码:
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();

欢迎进入武汉999论坛  |  发表评论  | 责任编辑: tiger
相关新闻
zhidaoMap525 zhidaoMap884 zhidaoMap1206 zhidaoMap779 sosoMap1647 infoMap1 sosoMap700 sosoMap1096 sosoMap1466 sosoMap1942 zhidaoMap4269 totalPage_zhidao=4557 totalPage_soso=2426 totalPage_info=1