@Transactional 仅在少数例外情况下传播事务 [英] @Transactional propogate transactions only for a few exceptions
本文介绍了@Transactional 仅在少数例外情况下传播事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使事务因所有未经检查的异常而失败,除了特定的未经检查的异常(在我的情况下 - DuplicateKeyException).如何使用 Spring 框架的 @Transactional 注释实现这种定制?
I am trying to make a transaction fail for all the unchecked exceptions except for a particular unchecked exception(in my case - DuplicateKeyException). How can I achieve this customization using @Transactional annotation of Spring framework ?
谢谢!
推荐答案
这样做:
public void driverMethod(){
try{
BeforeException()
}
catch(DuplicateKeyException e)
AfterException()
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
private BeforeException(){
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
private AfterException(){
}
这篇关于@Transactional 仅在少数例外情况下传播事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文