【发布时间】:2012-10-28 05:44:18
【问题描述】:
我们通过声明式方法使用事务管理,我们指定所有以 update* 开头的方法必须遵循事务。
假设我们有一个事务方法 updatePayroll() 在这个方法中我们调用了另外四个方法,但我们的要求是只有在前两个方法失败的情况下才回滚,否则不需要回滚。我不知道如何实现这一点,因为我的 updatePayroll() 是事务处理方法,所以如何告诉 spring 我们只需要两个方法的 updatePayroll()应该进行交易。
代码:
public void updatePayroll()
{
// below two methods of updateParyroll is required transaction where updatePayroll is transacted method through declarative approach.
updateLWPEmployees();
processSalary();
// below methods does not require transaction.
printSalarySlip();
sendEmail();
}
提前致谢。
【问题讨论】:
-
从这个方法中取出 printSalarySlip 和 sendEmail。
-
这是显式事务管理的一个明显案例,即使您可以尝试不同的 hack,这也会使您的代码非常难以理解,比如对于 6 个月后阅读它的人来说。跨度>
标签: java spring hibernate spring-transactions