Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

User Transaction on private method

 
dinu thamban
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Mark, this sounds good


-Dinu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic