gpt4 book ai didi

java - 我们可以在存储库层中使用一个 XA 资源和两个非 XA 资源吗

转载 作者:行者123 更新时间:2023-12-02 12:20:01 25 4
gpt4 key购买 nike

我们可以在同一存储库类中使用 xa 和非 xa 资源的组合吗?如果可以的话,有人可以解释一下它的行为方式以及交易将如何进行吗?目前,我们在存储库中使用 2 个 xa 资源和 2 个非 xa 资源。我们正在使用 glassfish 和 eclipselink。方法有没有问题。

最佳答案

您不能在单个事务中使用多个本地(=非 XA)数据源,但您可以在全局事务中组合多个 XA 资源,或者让非 XA 资源参与全局事务(使用 1 个 XA 数据源)(请参阅 LLR 1/2 )。

您可以考虑的事项:禁用对一个非 XA 数据源的事务支持,或使用 @TransactionAttribute(NOT_SUPPORTED) 将它们包装在 EJB 中以禁用事务。您也可以手动编排事务,但这可能会变得相当麻烦。

来自GlassFish 3 documentation :(旧版本,但同样适用于新版本)

Transaction Scope A local transaction involves only one non-XA resource and requires that all participating application components execute within one process. Local transaction optimization is specific to the resource manager and is transparent to the Java EE application.

In the GlassFish Server, a JDBC resource is non-XA if it meets either of the following criteria:

  • In the JDBC connection pool configuration, the DataSource class does not implement the javax.sql.XADataSource interface.

  • The Resource Type setting is not set to javax.sql.XADataSource.

A transaction remains local if the following conditions remain true:

  • One and only one non-XA resource is used. If any additional non-XA resource is used, the transaction is aborted.

  • No transaction importing or exporting occurs.

Transactions that involve multiple resources or multiple participant processes are distributed or global transactions. A global transaction can involve one non-XA resource if last agent optimization is enabled. Otherwise, all resourced must be XA. The use-last-agent-optimization property is set to true by default. For details about how to set this property, see Configuring the Transaction Service.

If only one XA resource is used in a transaction, one-phase commit occurs, otherwise the transaction is coordinated with a two-phase commit protocol.

关于java - 我们可以在存储库层中使用一个 XA 资源和两个非 XA 资源吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45854965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com