• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Transaction between 2 methods 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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
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 for wonderful reply
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle,
Can you point me to the page in the book where this is reference?
I'm having the 3rd Edition but could not locate it.
Sorry for the request.
Thanks.

Han Ming
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Men call me Jim. Women look past me to this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic