aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes User Transaction on private method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "User Transaction on private method" Watch "User Transaction on private method" New topic
Author

User Transaction on private method

dinu thamban
Greenhorn

Joined: Mar 07, 2006
Posts: 5
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

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
dinu thamban
Greenhorn

Joined: Mar 07, 2006
Posts: 5
Thanks Mark, this sounds good


-Dinu
 
Consider Paul's rocket mass heater.
 
subject: User Transaction on private method