• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Application Exception thrown by Bean with BMT

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EJB 2.0 specs says:
If bean using Bean Managed Transaction (BMT) demarcation throws application exception, container re-throws application exception.

However, specification does not mention about what happens to transaction associated with the Bean.
If bean instance called UserTransaction.setRollbackOnly() in method before throwing application exception, one needs to rollback transaction or commit it, isn't it? So who's responsible to do the same? Is it not Container? I think it's Container who co-ordinates with Transaction Manager. But if it's not the Container, please correct me and tell who does commit or rollback in the above mentioned case.

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

It depends on what type of bean you are looking at. For stateless session beans using BMT the spec says the following.

-----
If a stateless session bean instance starts a transaction in a business method, it must commit the transaction
before the business method returns. The Container must detect the case in which a transaction was
started, but not completed, in the business method, and handle it as follows:
- Log this as an application error to alert the system administrator.
- Roll back the started transaction.
- Discard the instance of the session bean.
- Throw the java.rmi.RemoteException to the client if the client is a remote client, or
throw the javax.ejb.EJBException if the client is a local client.
-----

The same applies for message driven beans, except for the last point because there is no client.

For stateful session beans the container can retain the transaction across multiple client calls and will therefore not rollback the transaction.

Kind regards
Christian
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
well.. my understanding is, if you are using BMT, then it's upto the bean provider to do all the transaction stuffs. So in this case .. the bean provider has to check the tx status usign UserTx.getStatus() and then do a commit() or rollback() based on it. So there's nothing the container can do.
 
Sandesh Tathare
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So sorry guys. I was bit lost in bean with CMT & BMT. :roll:

Whether to commit or rollback transaction is sole responsibility of the bean provider in case of bean using BMT and NOT the container.

I take back my question. Whatever specs says is correct. The good part is my understanding has become crystal clear now. Hope this confusion would help others also.

Regards,
Sandesh
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got confused by Christian and Sandesh. Based on what posted by Christian, the container will Rollback the Transcation even it's BMT bean, but later Sandesh said if this is BMT bean, then Bean provider to roll back?
Isn't it conflicting?
[ July 07, 2004: Message edited by: Hai Lin ]
 
Sandesh Tathare
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,

What Christian is pointing out is a case where bean does not end transaction started before completing the method. Remember, only Stateful Session bean can keep transaction open across multiple method calls and NOT Stateless Session Bean or Message-driven Bean can do it.

If bean instance uses BMT and throws Application Exception, before throwing an Application exception bean can either rollback or commit transaction by calling UserTransaction.commit() or UserTransaction.rollback(). Note here bean will get an opportunity to rollback or commit transaction.

If bean instance uses BMT and throws System Exception, Container marks for rollback a transaction that has been started, but not yet completed, by the bean instance. Note here bean MAY NOT get an opportunity to rollback or commit transaction.

So I need to revise my statment as below:
"Whether to commit or rollback transaction is responsibility of bean provider in case of bean using BMT throws Application exception and container rollbacks transaction when bean throws System Exception."

I hope this makes things very clear.

Regards,
Sandesh
 
please buy this thing and then I get a fat cut of the action:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic