Hibernate rollback method: rollback transaction
•
Java
rollback()
Example
Transaction tx = null;
try{
Session session = sessionFactory.openSession();
//定义Session对象
tx=session.beginTransaction(); //开启事务
UserForm uf = new UserForm(); //定义JavaBean示例
uf.setUsername(username); //设置JavaBean对象属性
uf.setPwd(pwd);
session.saveOrUpdate(uf); //定义保存对象方法
tx.commit(); //提交事务
}
catch(Exception e){
e.fillInStackTrace();
tx.rollback(); //回滚事务
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
