• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BMT not propogated to invoked beans

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic