2010-04-15 41 views
4

我無法找到在ejb中設置TransactionIsolation的方法。任何人都可以告訴我如何設置它?我正在使用持久性。如何在EJB中設置事務隔離?

我看了以下類: EntityManager,EntityManagerFactory,UserTransaction。他們都沒有像setTransactionIsolation或類似的方法。我們是否需要更改persistence.xml?

我剛剛讀了一本名爲Mastering EJB 3.0第4版的書。他們給了有關隔離級別了整整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的書,並使其在重量不必要:(重

回答

0

this

+0

喜竹, 你提到不包含READ_COMMITED或READ_UNCOMMITED或SERIALIZABLE或REPEATABLE_READ的任何名稱的頁面?這些隔離級別在您提到的頁面上?他們似乎與我在書中讀到的不同? – TCM 2010-04-15 05:24:08

+0

這些是JDBC隔離級別。請參閱http://docs.sun.com/app/docs/doc/820-7695/beamv?a=view – 2010-04-15 05:37:44

5

如EJB規範中說

交易不僅完成一個工作單元原子,,但它們也將工作單元彼此隔離,前提是系統允許同時執行多個工作單元。

  • 用於管理隔離級別的API是資源管理器特定的。 (因此,EJB體系結構未定義用於管理隔離級別的API。)
  • Bean提供程序在設置隔離級別時必須小心。大多數資源管理器 要求在事務內對資源管理器的所有訪問均使用相同的隔離級別完成。
  • 對於會話bean和消息驅動bean 與bean管理事務劃分,Bean提供者可以在企業bean的方法編程方式指定理想的隔離級別,使用資源管理器特定的API。例如,java.sql.Connection.setTransactionIsolation
  • 容器提供應確保所提供的適當隔離級別,以保證實體bean的數據一致性
  • 如果多個企業Bean訪問相同的資源管理器
  • 附加必須小心在同一筆交易中。 必須避免所請求隔離級別的衝突。

我希望它能夠fullfil您的需求

相關問題