简体   繁体   English

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

[英]How do i set the Transaction Isolation in EJB?

I am not able to find a way to set TransactionIsolation in ejb. 我无法找到在ejb中设置TransactionIsolation的方法。 Can anybody tell me how do i set it? 任何人都可以告诉我如何设置它? I am using persistence. 我正在使用持久性。

I have looked the following classes : EntityManager , EntityManagerFactory, UserTransaction. 我查看了以下类:EntityManager,EntityManagerFactory,UserTransaction。 None of them seems to have any method like setTransactionIsolation or such. 他们似乎都没有像setTransactionIsolation这样的方法。 Do we need to change persistence.xml? 我们需要更改persistence.xml吗?

I just read a book named Mastering EJB 3.0 4th edition. 我刚看了一本名为Mastering EJB 3.0 4th edition的书。 They gave a full 10 page theory about Isolation level that this problems occur and that occurs and such things but at the end they gave this paragraph :- 他们给出了关于隔离级别的完整的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. "

What exactly does it mean? 究竟是什么意思? What is meant by resource level APIs? 资源级API的含义是什么? Please help me. 请帮我。 If persistence has no way to set Isolation Level then why do they give such huge theory in an EJB book and make it heavy in weight unnecessarily :( 如果持久性无法设置隔离级别,那么为什么他们会在EJB书中提供如此巨大的理论并使其在重量上不必要地重:(

As said by EJB specification 正如EJB规范所说的那样

Transactions not only make completion of a unit of work atomic, but they also isolate the units of work from each other , provided that the system allows concurrent execution of multiple units of work. 事务不仅使完成一个工作单元原子, 而且它们还将工作单元彼此隔离 ,前提是系统允许并发执行多个工作单元。

  • The API for managing an isolation level is resource-manager-specific . 用于管理隔离级别的API 是特定于资源管理器的 (Therefore, the EJB architecture does not define an API for managing isolation levels .) (因此,EJB体系结构没有定义用于管理隔离级别的API 。)
  • The Bean Provider must take care when setting an isolation level. 设置隔离级别时,Bean Provider必须小心。 Most resource managers require that all accesses to the resource manager within a transaction are done with the same isolation level . 大多数资源管理器要求事务对资源管理器的所有访问都使用相同的隔离级别
  • For session beans and message-driven beans with bean-managed transaction demarcation , the Bean Provider can specify the desirable isolation level programmatically in the enterprise bean's methods, using the resource-manager specific API . 对于具有bean管理的事务划分的会话bean和消息驱动的bean,Bean Provider可以使用特定于资源管理器的API以编程方式在企业bean的方法中指定所需的隔离级别。 For example, java.sql.Connection.setTransactionIsolation 例如,java.sql.Connection.setTransactionIsolation
  • The container provider should insure that suitable isolation levels are provided to guarantee data consistency for entity beans 容器提供程序应确保提供合适的隔离级别以保证实体bean的数据一致性
  • Additional care must be taken if multiple enterprise beans access the same resource manager in the same transaction. 如果多个企业bean在同一事务中访问同一资源管理器,则必须进一步小心。 Conflicts in the requested isolation levels must be avoided. 必须避免在请求的隔离级别中发生冲突。

I hope it can fullfil your needs 我希望它能满足你的需求

看到这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM