• 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

Required/RequiresNew for 2 method in the same bean

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, I got this already
 
reply
    Bookmark Topic Watch Topic
  • New Topic