wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes A question on transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "A question on transactions" Watch "A question on transactions" New topic
Author

A question on transactions

lokesh sree
Ranch Hand

Joined: Oct 27, 2009
Posts: 99

Hi Ranchers,

I have a question related to stateless beans, transactions and transaction attributes.
I have a stateless bean MyBean with two functions - funcA() annotated with a transaction attribute of NEVER and funcB() annotated with a attribute of REQUIRED.
When funcA() gets invoked from some other stateless bean, funcA() runs without a transaction as it is annotated with an attribute of NEVER. But, I see that if funcB() is called from funcA(), even funcB() runs without a transaction. Is this the expected behaviour? Is it because call to funcB() is a direct call from funcA() and hence the container does not care about the transaction attributes present on funcB()? Can some one provide information on this?

One additional observation is that from funcA(), if funcB() is invoked via the local interface of MyBean rather than making a direct call, funcB() indeed runs in a transaction.
Is this the only way to have funcB() running in a transaction when called from funcA()?


Lokesh
( SCBCD 5, CCENT, SCJP 5 )
Christian Gossart
Ranch Hand

Joined: Mar 13, 2008
Posts: 34
If your funcB() call from funcA() is on the same object (like you could use this.funcB() in your code), the EJB container has no way to intercept the call and provide the transaction mechanism around funcB().
The EJB specification says somewhere that transaction annotations (and all interceptors I think) are processed only for calls using an "EJB reference", not for pojo internal calls. That's what you observe using the local interface of your bean.
I really lost hours of debugging on a problem of this kind (REQUIRED_NEW that did not create a new transaction), so now I never forget this


Christian Gossart
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9955
    
163

Christian Gossart wrote:
The EJB specification says somewhere that transaction annotations (and all interceptors I think) are processed only for calls using an "EJB reference", not for pojo internal calls.


That's correct, plain Java calls will not introduce EJB semantics. Here's an example on how to invoke a second method from the bean's business method, if you want to introduce the EJB semantics.


[My Blog] [JavaRanch Journal]
lokesh sree
Ranch Hand

Joined: Oct 27, 2009
Posts: 99


Yes, I suspected that the problem was due to the plain java call and made a call through the bean interface to get the required behavior. But I just wanted to get it confirmed. Thanks to both of you guys for the replies and the confirmation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question on transactions
 
Similar Threads
My SCEA Part 1Study Notes
EJB Notes I prepared during my preparation for SCBCD
Transaction context
Passed SCBCD 5.0 :)
Stateless beans and SessionSynchronization