Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Transaction rollback...and being user friendly

 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a transaction rolls back the client receives the equivalent of a runtime exception. This means that, like any runtime exception (uncaught), usually the stack trace will appear on the console, or the application will stop working. For instance, when I get a NullPointerException for my application (which is a runtime exception), I get the stack trace of what happened (like: something bad happened). This is fine for CMT, as it's the container which manages transactions (unless the bean's developer can force it to rollback), and if it decides to rollback a transaction it's probably because something bad happened; but BMT, it's be bean developer who has got complete control over transaction behaviour, and if a rollback is thrown, this doesn't mean necessarily that something bad as a runtime exception occurred. The bean developer may decide to rollback a transaction if he realizes for instance that there were no enough funds in a bank account: now, is this a reason enough to throw the equivalent of a system exception?
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In case of a BMT if there is a situation where you need to just rollback the transaction then you can call setRollBackOnly in the code and probably throw an application specific exception, which would be more useful in you application and you can set up the client to expect the exception and do the appropriate things instead of crashing down the bean by a system exception. I hope I answered your question.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,

If I understood your question right you expect a "TransactionRolledBackException" in each case the transaction rolls back. That's not true. Even for CMP, the spec in 18.3.6 says:

However, the Container should not throw the java.rmi.RemoteException or
javax.ejb.EJBException if the Container performs a transaction rollback because the instance
has invoked the setRollbackOnly() method on its EJBContext object. In this case, the Container
must rollback the transaction and pass the business method result or the application exception
thrown by the business method to the client.


So it is possibel to rollback a transaction without exception. Or did I undestand you wrong?

Severin
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Severin St�ckli:
Hi Marc,

If I understood your question right you expect a "TransactionRolledBackException" in each case the transaction rolls back. That's not true. Even for CMP, the spec in 18.3.6 says:

However, the Container should not throw the java.rmi.RemoteException or
javax.ejb.EJBException if the Container performs a transaction rollback because the instance
has invoked the setRollbackOnly() method on its EJBContext object. In this case, the Container
must rollback the transaction and pass the business method result or the application exception
thrown by the business method to the client.


So it is possibel to rollback a transaction without exception. Or did I undestand you wrong?

Severin




Thank you Severin, this is exactly the answer that I was looking for.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic