【问题标题】:How do i set the Transaction Isolation in EJB?如何在 EJB 中设置事务隔离?
【发布时间】:2010-04-15 05:12:27
【问题描述】:

我无法找到在 ejb 中设置 TransactionIsolation 的方法。谁能告诉我如何设置它?我正在使用持久性。

我看过以下课程: 实体管理器,实体管理器工厂,用户事务。他们似乎都没有像 setTransactionIsolation 这样的方法。我们需要更改persistence.xml吗?

我刚刚读了一本名为 Mastering EJB 3.0 4th edition 的书。他们给出了整整 10 页的关于隔离级别的理论,即这个问题的发生和那个发生等等,但最后他们给出了这一段:-

"As we now know, the EJB standard does not deal with isolation levels directly,
and rightly so. EJB is a component specification. It defines the behavior and
contracts of a business component with clients and middleware infrastructure
(containers) such that the component can be rendered as various middleware
services properly. EJBs therefore are transactional components that interact
with resource managers, such as the JDBC resource manager or JMS resource
manager, via JTS, as part of a transaction. They are not, hence, resource
components in themselves. Since isolation levels are very specific to the
behavior and capabilities of the underlying resources, they should therefore be
specified at the resource API levels. "

具体是什么意思?资源级 API 是什么意思?请帮我。如果持久性无法设置隔离级别,那么为什么他们在 EJB 书中给出如此庞大的理论并不必要地加重它的重量:(

【问题讨论】:

    标签: java jpa ejb


    【解决方案1】:

    正如 EJB 规范所说的

    事务不仅使一个工作单元的完成具有原子性,而且它们还将工作单元彼此隔离,前提是系统允许同时执行多个工作单元。

    • 用于管理隔离级别的 API特定于资源管理器。 (因此,EJB 架构没有定义用于管理隔离级别的 API。)
    • Bean Provider 在设置隔离级别时必须小心。大多数资源管理器 要求事务中对资源管理器的所有访问都使用相同的隔离级别
    • 对于会话 bean 和消息驱动 bean具有 bean 管理的事务划分,Bean Provider 可以在企业 bean 的方法中以编程方式指定所需的隔离级别,使用资源管理器特定API。例如,java.sql.Connection.setTransactionIsolation
    • 容器提供者应确保提供合适的隔离级别以保证实体 bean 的数据一致性
    • 如果多个企业 bean 在同一个事务中访问同一个资源管理器,则必须格外小心。 必须避免请求的隔离级别发生冲突。

    希望能满足你的需求

    【讨论】:

      【解决方案2】:

      this

      【讨论】:

      • 您好 Chuk,您引用的页面不包含任何名称 READ_COMMITED 或 READ_UNCOMMITED 或 SERIALIZABLE 或 REPEATABLE_READ?您提到的页面上是否有这些隔离级别?它们似乎与我在书中看到的不同?
      • 这些是 JDBC 隔离级别。见docs.sun.com/app/docs/doc/820-7695/beamv?a=view
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      • 1970-01-01
      • 2011-03-31
      • 2013-11-20
      • 2014-03-07
      相关资源
      最近更新 更多