批量修改:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hqlUpdate = "update Customer set name = :newName where name=ldName";
int updatedEntities = s.createQuery( hqlUpdate )
.setString( "newName", newName )
.setString( "oldName", oldName )
.executeUpdate();
tx.commit();
session.close();
批量删除:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String hqlDelete = "delete Customer where name =ldName";
int deletedEntities = s.createQuery( hqlDelete )
.setString( "oldName", oldName )
.executeUpdate();
tx.commit();
session.close();
也可以使用JDBC API来操作:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Connection con=session.connection();
PreparedStatement stmt=con.prepareStatement("update Customer set name = :newName where name=ldName");
stmt.executeUpdate();
tx.commit();
session.close();
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Connection con=session.connection();
PreparedStatement stmt=con.prepareStatement("delete Customer where name =ldName");
stmt.executeUpdate();
tx.commit();
session.close();
hibernate3.0以上处理批量删除批量修改
最新推荐文章于 2018-12-19 19:50:18 发布