@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屋!
查看全文