hiberante中的批量更新和指删除

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();

本文摘自别处。

你可能感兴趣的:(Hiberante)