• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Required/RequiresNew for 2 method in the same bean

 
Gus Mus
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
[ February 28, 2003: Message edited by: Gus Mus ]
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gus Mus:

the question is will Container begin new Transaction for method B() ? (Because it's Requires new ?)

Yes.
Originally posted by Gus Mus:

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 ?

This is the job of the container to implement. It doesn't matter whether the call is in the same bean, it is still part of the EJBObject and subject to the same rules as any other EJB Call. Rest assured, if the method is marked "RequiresNew" then the Container will always start a new transaction.
 
Gus Mus
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this implementation depend or vary between the Container ?
Since I tried to make one example in this case, and the transaction was completed after method A() was finished not after method B().
If I called method B() from method A() remotely or locally (by obtaining again the bean from JNDI and called method B() via this bean) then the transaction is completed on method B.
And if the client called method B() directly not from method A() then it's also fine.
This is very strange ... it seems like container
doesn't create new transaction if the method is called from the method in the same bean.
I think I don't make any mistake on transaction declaration in DD
[ March 03, 2003: Message edited by: Gus Mus ]
 
k space
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, appserver won't do anything if method B() was invoked directly (i.e. not going through it's remote or local interface) within method A(). It's just like a normal java call.
Method B() must be invoked through its remote or local interface (in your 2nd and 3rd cases), so that the appserver can intercept the call and do whatever it needs to do, e.g. creating a new transaction.
 
Gus Mus
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I got this already
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic