aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes BMT not propogated to invoked beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "BMT not propogated to invoked beans" Watch "BMT not propogated to invoked beans" New topic
Author

BMT not propogated to invoked beans

Amardeep Verma
Greenhorn

Joined: May 28, 2003
Posts: 7
Hi,
I have a peculiar problem. I have 3 Stateless Session Beans. All of these beans have Bean Managed Transaction.

Let us say BeanA, BeanB and BeanC are the 3 beans. There are 3 methods inside each Bean, ie Method1(), Method2() and Method3() inside BeanA, BeanB and BeanC respectively. Method2() and Method3() have to be invoked from Method 1(). Consider the following stub of BeanA

BeanA:
public void Method1()
{
UserTransaction ut;
//Do some Initialisation
...
...
try
{
ut.begin();
//Do Some JDBC Operations
......

BeanB.Method2(); //Invoking Method2 of EJB Bean2.

BeanC.Method3(); //Invoke the method3 of Bean3.

//Do Some more JDBC Operations
......

ut.commit();
}catch (Exception e)
{
ut.rollback();
}
}

The problem is this, the status of the UserTransaction inside BeanA.Method1() is "0"(Zero), which corresponds to "ACTIVE". However the status of the UserTransaction inside BeanB.Method2() and BeanC.Method3() is 6, which corresponds to "NO_TRANSACTION".
The consequence of this is, if there is any exception, the changes made by BeanA are rolled back, but not the changes made by BeanB or by BeanC.
There is no commit or rollback or beginning of a new transaction or ending of any transaction inside BeanB or BeanC.

So my question is this, why is the transaction not getting propagated across Beans? And what can I do, to get the transaction propagated across Bean boundaries?
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

why is the transaction not getting propagated across Beans?


The EJB spec is your friend - here's what 17.6.1 of EJB 2.1 spec says


If the client request is not associated with a transaction and the instance is not associated with a transaction, or if the bean is a message-driven bean, the container invokes the instance with an
unspecified transaction context.
� If the client request is associated with a transaction T1, and the instance is not associated with a transaction, the container suspends the client�s transaction association and invokes the method with an unspecified transaction context. The container resumes the client�s transaction association (T1) when the method completes. This case can never happen for a message-driven bean or for the invocation of a method on the web service endpoint interface of a stateless session
bean.
� If the client request is not associated with a transaction and the instance is already associated with a transaction T2, the container invokes the instance with the transaction that is associated with the instance (T2). This case can never happen for a stateless session bean or a message-
driven bean.
� If the client is associated with a transaction T1, and the instance is already associated with a transaction T2, the container suspends the client�s transaction association and invokes the method with the transaction context that is associated with the instance (T2). The container
resumes the client�s transaction association (T1) when the method completes. This case can never happen for a stateless session bean or a message-driven bean.



And what can I do, to get the transaction propagated across Bean boundaries?


Not possible with JTA unless you can get to the transaction manager apis and code.
I have heard people say that Spring has a way to do it, but that's just hearsay.

ram.
 
wood burning stoves
 
subject: BMT not propogated to invoked beans