tags:

views:

178

answers:

2

Hello,

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

+1  A: 

See this

Chuk Lee
Hi Chuk,the page you referred doesn't contain any name of READ_COMMITED or READ_UNCOMMITED or SERIALIZABLE or REPEATABLE_READ? Are these Isolation levels on the page which you referred? They seem to be different from what i read in book?
Ankit Rathod
Those are JDBC isolation levels. See http://docs.sun.com/app/docs/doc/820-7695/beamv?a=view
Chuk Lee
+1  A: 

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

Arthur Ronald F D Garcia