• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on transactions

 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()?
 
Christian Gossart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic