• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question on EJB 3 IN ACTION - application exception rollback

 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • 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 ?
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Amit Suresh Pawar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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.............
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • 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
 
sandeeprajsingh tandon
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic