• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question on EJB 3 IN ACTION - application exception rollback

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I come through the code listing below on pg193 to pg194 of book EJB 3 IN ACTION



where the explanation on pg195 state that
"By default, application exceptions do not cause an automatic CMT rollback since the rollback element is defaulted to false. However, setting the element to true tells the container that it should roll back the transaction before the exception is passed on to the client. ... means that whenever a CreditValidationException, CreditProcessingException, or DatabaseException is thrown, the transaction will be rolled back ..."

my question is ,
1) if DatabaseException is not being applied with @ApplicationException annotation, it is a RuntimeException and thus is a system exception which will be wrapped in EJBException, so surely it will be rolled back, am I right ?
2) now follow the code listed, DatabaseException is applied with @ApplicationException annotation, thus it is an application exception. And with the rollback=false, the transaction should not rollback right ?
 
Ranch Hand
Posts: 133
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lee Kian Giap wrote:

1) if DatabaseException is not being applied with @ApplicationException annotation, it is a RuntimeException and thus is a system exception which will be wrapped in EJBException, so surely it will be rolled back, am I right ?



That's right.

2) now follow the code listed, DatabaseException is applied with @ApplicationException annotation, thus it is an application exception. And with the rollback=false, the transaction should not rollback right ?



It will not rollback the current transaction.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

From above discussion,is it means that whenever a CreditValidationException, CreditProcessingException, or DatabaseException is thrown, the transaction will be rolled back,even if the DatabaseException has set rollback=false?
Please help...............

I'm confused.............
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


in the above code, the rollback property is setted to false..
so it's mean that whenever the DatabaseException is thrown, it wouldn't rollback the transaction..


From the above code, assume that validateCredit(customer) and chargeCustomer(customer,item) done successfully, but the removeItemFromBiddin(item) throws DatabaseException..
because we set the rollback property to false for DatabaseException, so it wouldn't rollback transaction..
its mean that the customer charged for that item and the item is still not removed from bidding..

Please correct me if i'm wrong..

Thanks
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leonardo Carreira wrote:

in the above code, the rollback property is setted to false..
so it's mean that whenever the DatabaseException is thrown, it wouldn't rollback the transaction..


From the above code, assume that validateCredit(customer) and chargeCustomer(customer,item) done successfully, but the removeItemFromBiddin(item) throws DatabaseException..
because we set the rollback property to false for DatabaseException, so it wouldn't rollback transaction..
its mean that the customer charged for that item and the item is still not removed from bidding..

Please correct me if i'm wrong..

Thanks




Yes its correct.Item will not be removed from bidding.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic