How to set transaction isolation in EJB?

I cannot find a way to set TransactionIsolation in ejb. Can someone tell me how I installed it? I use perseverance.

I looked at the following classes: EntityManager, EntityManagerFactory, UserTransaction. None of them seem to have a setTransactionIsolation method or such. Do I need to modify persistence.xml?

I just read a book called Mastering EJB 3.0 4th Edition. They gave a complete 10-page theory about the level of isolation, that these problems arise, and what happens, and such things, but in 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 this mean? What does resource level APIs mean? Please help me. If perseverance does not have a way to establish the level of isolation, then why do they give such a huge theory in the EJB book and make it heavy in weight without the need: (

+4
source share
2 answers

See this

0
source

As stated in the EJB specification

Transactions not only complete the work of a unit of atom, but also isolate work units from each other , provided that the system allows the simultaneous execution of several units of work.

  • The API for controlling the isolation level is resource dependent . (Therefore, the EJB architecture does not define an API for managing isolation levels .)
  • The Bean provider must monitor the isolation level. Most resource managers require that all calls to the resource manager in a transaction be performed with the same isolation level .
  • For a beans session and message-driven beans with a bean-structured transaction demarcation, the Bean provider can programmatically specify the desired isolation level at the enterprise bean s methods using the resource manager API . For example, java.sql.Connection.setTransactionIsolation
  • The container provider must ensure that appropriate isolation levels are provided to ensure data consistency for the beans object.
  • Extra care should be taken if multiple beans enterprises are accessing the same resource manager in the same transaction. Conflicts at the requested isolation levels should be avoided.

I hope that he can fully satisfy your needs.

+5
source

Source: https://habr.com/ru/post/1306995/


All Articles