带有支持传播的春季交易 [英] Spring Transactions With Supports Propagation
问题描述
我想了解使用Propagation Supports进行春季交易的用法. Java文档提到如果从事务内调用具有@Transactional(propagation = Propagation.SUPPORTS)
的方法,则该方法支持该事务,但是如果不存在任何事务,则该方法将以非事务方式执行.
I would like to understand the use of having a spring transaction with Propagation Supports. The java docs mention that if the method which has @Transactional(propagation = Propagation.SUPPORTS)
is called from within a transaction it supports the transaction but if no transaction exists, the method is executed non-transactionally.
这是否已经成为春季交易的行为,而与Propagation.SUPPORTS
无关?
Isn't this already the behavior of spring transactions irrespective of Propagation.SUPPORTS
?
public class ServiceBean {
@Transactional(propagation = Propagation.SUPPORTS)
public void methodWithSupportsTx() {
//perform some database operations
}
}
public class OtherServiceBean {
@Transactional(propagation = Propagation.REQUIRED)
public void methodWithRequiredTx() {
//perform some database operations
serviceBean.methodWithSupportsTx();
}
}
在上面的代码示例中,无论methodWithSupportsTx()
是否具有@Transactional(propagation = Propagation.SUPPORTS)
注释,它都将在事务中执行,具体取决于methodWithRequiredTx()
是否具有@Transactional
注释,对吧?
In the above code example, irrespective of whether methodWithSupportsTx()
has @Transactional(propagation = Propagation.SUPPORTS)
annotation it would be executed in a transaction depending on whether methodWithRequiredTx()
has @Transactional
annotation, right?
那么具有传播级别支持的需求/用途是什么?
So what's the need/use of having a propagation level SUPPORTS?