This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
For instance I have one Stateless Session Bean with Container Managed Transaction, which consists of 2 Methods, lets say A() and B() For some reasons the transaction attribute for method A() is Required and for method B() is RequiresNew. The problem is method A() call method B() in the same bean and inside container, the question is will Container begin new Transaction for method B() ? (Because it's Requires new ?) I am wondering ... because Container start the new transaction by EJBObject (that decorates the Stateless Bean) and when client call method A() of the bean then container start the transaction, but method A in the same bean call method B then how container know if it needs to start the new transaction ? Thank you for any help
If you use this.methodB() or its equivalent (just use methodB()) then the container won't know -- but that's not the way you're supposed to call methods in the same bean. What you have to do is: (1) Get the EJBContext of the bean (2) Get the EJBObject from the context (3) Cast the EJBObject to the Remote Interface (4) Call methodB() on the newly cast object. This is described in Richard Monson-Haefel's book in detail with code. This way the container DOES know about the call, and can start the second transaction accordingly. Kyle
I've lost count of the number of books and articles I've read on EJB lately, and I have never seen this mentioned anywhere. I just ran up against this last week, and I had to create a reproducable test case for BEA to take a look at it. After a few hours of going over the spec with an engineer, it was concluded that the spec is unclear. He suggested the same solution presented above, and it works. However, now that I know the solution and why it works, I understand why it shouldn't have worked the way I was doing it. In any case, since you're sitting in the bean itself, you can go through the local interface instead of the remote:
I just wish I had found this message last week.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Transaction between 2 methods in the same bean