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

a mock question about transcation

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which one of the following statements regarding the client view of exceptions received from an enterprise bean invocation is correct?



1. The client can safely continue the transaction by retrying the operation if an application exception is received.



2. The client can safely continue the transaction by retrying the operation if an application exception is received, but only after checking the transaction has not been marked for rollback.



3. The client can safely continue the transaction by retrying the operation if a non-application exception is received.



4. A local client cannot continue a transaction if javax.transaction.TransactionRolledbackLocalException is received.



5. A remote client cannot continue a transaction if javax.transaction.TransactionRolledbackException is received.

the answer is 5,why 4 is incorrect
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.transaction.TransactionRolledbackLocalException does not exist.
It is javax.ejb.TransactionRolledbackLocalException

---

My question is; why is 1 not correct ?

If a bean throws an application exception, the transaction may be continued. Since application exceptions do not have impact on the transaction itself.

This is only true for statefull session beans and entit beans. Stateless and message driven beans must end the transaction before the method ends, so you cannot retry (a retry would mean a new transaction).

Could that be the reason why 1 is fault ?
 
chao cai
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answers 1 and 2 are incorrect. It is potentially dangerous retrying to continue with a transaction after receiving an application exception because it is not always possible to determine the state of the enterprise bean. For example, if the container started a transaction just before invoking an enterprise bean with container-managed transaction and the enterprise bean throws an application exception and does not mark the transaction for rollback, the container commits the transaction before re-throwing the application exception to the client. In this scenario, it is not possible for the client to continue with the transaction on receiving the application exception.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an alternative scenario. A transaction begins in a CMT bean (A) which propagates into bean B. If an application exception is thrown in bean B, it will be received by bean A. Let us say that bean A handles the exception. At this point, nothing is committed and it would be quite safe for bean A to take corrective action in the same transaction. (This assumes that the Bean Provider has ensured that the instance of bean B is in a state such that an attempt by bean A to continue and/or commit the transaction does not result in loss of data integrity.)
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic