• 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

User Transaction on private method

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am using stateless session bean with bean managed transaction.
I wanted user transaction on a method and this is a private method

private void sent sendToDB {
UserTransaction ut ..

ut.begin

try {
if (ut != null) {
ut.commit();
}
}
}

My question is can I have User Transaction in private method.

-Dinu
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not, the code is still in the Session Bean.

But, wait, why is this private method in the Bean. I think a better approach for EJBs, is to not include logic and code inside the Bean, but to use a Plain Old Java Object that is called from the bean. Have both implement the same interface and just pass the call to the POJO through the Session Bean. Then set your Transaction in the Session Bean and the calls to the POJO will be wrapped in that Transaction. You can also always use JTA to make transactions in any piece of code, no matter where it resides.

Mark
 
dinu thamban
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark, this sounds good


-Dinu
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic