• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I use UserTransaction within a CMP Session bean?  RSS feed

 
Shimi Avizmil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically the problem is as follow:
I have the following method in a Statefull session bean:
public Whatever do()
{
processSomething();
notify();
}
the notify() basically notifying the client that then query for the something that was processed in the processSomething() method.
THE PROBLEM is that the changes have not been committed yet as the do() method is not finished yet and the container has not committed the changes.
THE QUESTION is - can I use UserTransaction inside
processSomething to commit the changes and leave the bean as CMP? I want to leave it as CMP as there are more methods on the bean and I don't want to have to manage the transactions for them.
Anyone has any other ideas?
Thanks in advanced.
 
Manish Kamat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can either set transaction attributes for methods you want in deployment descriptor or you can use javax.transaction.usertransaction and put transaction boundaries across methods you want
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An EJB must either be CMT or BMT, it can not be both. Therefore, if you would like some methods in a Session Bean to be CMT and others to be BMT, then you should break your single Session Bean into two separate Session Beans.
Trying to access the UserTransaction in a CMT bean will cause a IllegalStateException exception.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!