my dog learned polymorphism*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes question on EJB 3 IN ACTION - application exception rollback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "question on EJB 3 IN ACTION - application exception rollback" Watch "question on EJB 3 IN ACTION - application exception rollback" New topic
Author

question on EJB 3 IN ACTION - application exception rollback

Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
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 ?


SCJP 6, SCWCD 5, SCBCD 5
Krzysztof Koziol
Ranch Hand

Joined: Nov 19, 2006
Posts: 133

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.


SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCEA/OCMJEA 5.0
Amit Suresh Pawar
Ranch Hand

Joined: Dec 09, 2008
Posts: 30
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.............


Amit S. Pawar
SCJP,SCWCD,OCA
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489



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


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
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.
 
Consider Paul's rocket mass heater.
 
subject: question on EJB 3 IN ACTION - application exception rollback
 
Similar Threads
How a transaction is commited in a CMT
Rollback
Enthuware Question doubt
Is that RuntimeException subclasses are system Exceptions or application exception.
Application Exceptions...