[英]Transaction management by multiple datasources
If we are performing a transaction using a datasource (named 'ABC') and inside that transaction we need a different connection object from other datasource (named 'DEF') 如果我们使用数据源(名为“ ABC”)执行事务,并且在该事务内部,我们需要与其他数据源(名为“ DEF”)不同的连接对象
So what we are currently doing is, we set the @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) on the EJB method, In the same method we are writing the code for getting the new connection from other datasource (named 'DEF'). 因此,我们目前正在做的是,在EJB方法上设置@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)。在同一方法中,我们正在编写用于从其他数据源(名为“ DEF”)获取新连接的代码。
The reason why we are doing this is 'There is transaction going on that is using a connection from datasource named 'ABC', but now we need to perform some other operation in other transaction so we need a connection from other datasource named 'DEF', that is why we need to suspend the first transaction by saying NOT_SUPPORTED and do the necessary operation on the new connection and then again resume the same old transaction' 我们这样做的原因是“正在进行事务,它正在使用来自名为“ ABC”的数据源的连接,但是现在我们需要在其他事务中执行其他操作,因此我们需要与来自名为“ DEF”的其他数据源的连接,这就是为什么我们需要通过说出NOT_SUPPORTED来暂停第一个交易并在新连接上进行必要的操作,然后再次恢复相同的旧交易'
Please validate my understanding. 请验证我的理解。
TransactionAttributeType.NOT_SUPPORTED
is not what you need, if I understand your scenario correctly. 如果我正确理解您的情况,则不需要TransactionAttributeType.NOT_SUPPORTED
。
You need to annotate the method with TransactionAttributeType.REQUIRES_NEW
. 您需要使用TransactionAttributeType.REQUIRES_NEW
注释该方法。 This will suspend the outer transaction and create a new independent transaction. 这将暂停外部事务并创建一个新的独立事务。
You're reasoning is sound. 你的推理是合理的。 If you're using Spring, there is a more simple way: 如果您使用的是Spring,则有一种更简单的方法:
@Transactional( "DEF", propagation: Propagation.NESTED )
This will create always create a new transaction using the TransactionManager
DEF
这将始终使用TransactionManager
DEF
创建一个新事务
Unfortunately, the EJB standard doesn't support NESTED
. 不幸的是,EJB标准不支持NESTED
。
Transactions can be classified into two categories 交易可分为两类
For more details refer J2EE online documents.. 有关更多详细信息,请参阅J2EE联机文档。
Cheers! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.