随笔-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 阅读(1502) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航:
 
MSN:envoydada@hotmail.com QQ:34935442