如何在EJB中设置事务隔离?

时间:2010-04-15 05:12:27

标签: java jpa ejb

我无法找到在ejb中设置TransactionIsolation的方法。任何人都可以告诉我如何设置它?我正在使用持久性。

我查看了以下课程: EntityManager,EntityManagerFactory,UserTransaction。他们似乎都没有像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书中提供如此庞大的理论并使其在重量上不必要地增加:(

2 个答案:

答案 0 :(得分:5)

如EJB规范所述

  

只要系统允许并发执行多个工作单元,事务不仅会使工作单元完成原子,,而且还会将工作单元彼此隔离

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

我希望它可以满足您的需求

答案 1 :(得分:-1)

请参阅this