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

发布于 2024-08-29 10:30:38 字数 1131 浏览 3 评论 0原文

我无法找到在 ejb 中设置 TransactionIsolation 的方法。有人能告诉我如何设置吗?我正在用坚持。

我看过以下课程: EntityManager、EntityManagerFactory、用户事务。他们似乎都没有像 setTransactionIsolation 之类的方法。我们需要更改 persistence.xml 吗?

我刚刚读了一本名为 Mastering EJB 3.0 第四版的书。他们给出了一个完整的 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 书中给出如此庞大的理论并不必要地加重它的分量:(

I am not able to find a way to set TransactionIsolation in ejb. Can anybody tell me how do i set it? I am using persistence.

I have looked the following classes :
EntityManager , EntityManagerFactory, UserTransaction. None of them seems to have any method like setTransactionIsolation or such. Do we need to change persistence.xml?

I just read a book named 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 :-

"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? 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 :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乖乖兔^ω^ 2024-09-05 10:30:38

正如 EJB 规范所述

事务不仅使工作单元的完成成为原子的,而且还使工作单元彼此隔离,前提是系统允许多个工作单元并发执行。

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

希望它能够满足您的需求

As said by EJB specification

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. (Therefore, the EJB architecture does not define an API for managing isolation levels.)
  • The Bean Provider must take care when setting an isolation level. 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. For example, java.sql.Connection.setTransactionIsolation
  • The container provider should insure that suitable isolation levels are provided to guarantee data consistency for entity beans
  • Additional care must be taken if multiple enterprise beans access the same resource manager in the same transaction. Conflicts in the requested isolation levels must be avoided.

I hope it can fullfil your needs

娇纵 2024-09-05 10:30:38

请参阅

See this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文