aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Transaction Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Transaction Question" Watch "Transaction Question" New topic
Author

Transaction Question

Ashley Bideau
Ranch Hand

Joined: Apr 22, 2006
Posts: 40
Given:
Bean A with transaction attributes of "RequiresNew" for all its methods.
Bean B with transaction attributes of "Supports" for all its methods.
A client having a transaction context calls a method mA() on bean A, which in turns calls a method mB() on Bean B.
Assuming all invocations are local, which of the following statements is correct if mB() encounters a system exception?



Select 2 correct options

a The client's transaction will be marked for roll back.

b The client will get a javax.ejb.EJBException but it can continue with the same transaction.

c The client will get a javax.ejb.TransactionRolledbackLocalException

d mA() will get a javax.ejb.TransactionRolledbackLocalException

e The bean A instance will NOT be discarded.

f Changes made to the database by mA(), will be commited.
Rajesh Chande
Greenhorn

Joined: Jun 28, 2006
Posts: 18
Hello Ashley,

I would normally opt for "a" and "c" on the following basis:

req. New supports
client ------> a.mA -------> b.mb
T1 T1
Sys Ex.

so - T1 marked for rollback.
- Client will get javax.ejb.TransactionRolledbackLocalException

Anybody.. correcting me?
TeGo Gokhale
Greenhorn

Joined: Jul 09, 2006
Posts: 11
I thin correct answer is B and D

with requiresnew a new tx was started.

So say client' stx was txcl
mA() would suspend txcl and would run in new txnew
mB() would also run in txnew.

So on system exception txnew would be rolled back. so mA() would get txrolledback excptn.

Container would give ejbexception to client. But clients txcl is still alive and he can continue with it.
paresh vernekar
Ranch Hand

Joined: Jul 10, 2006
Posts: 52
Hi,
I think the correct answers are d & e.
For bean B, the client is bean A.Since bean A is running in a new transaction and bean B runs in the same transaction, when exception occurs in bean B, it would be bean A which receives the javax.ejb.TransationRolledbackLocalException.Also since the exception has occurred in bean B, there is no need to discard the instance of bean A.
Option a is not correct because the exception doesnot occur in client transaction
Option b is not correct because for bean B, the client is bean A
Option c is not correct for the same reason
Option f is not correct because the exception occurred when bean B was running in the transaction context of bean A
Please correct me if the above reasoning is wrong

Regards,
Paresh Vernekar
TeGo Gokhale
Greenhorn

Joined: Jul 09, 2006
Posts: 11
May be you are correct, but what i think is since the transaction in which Bean A was running has been marked to rollback, there is no reason for container not discarding beanA.

Option B seems to be correct because though beanA is client to beanB but the component who invoked mA() is client to beanA who would get ejbException and that is the client which is reffered to in option B
Abhinav Prakash
Greenhorn

Joined: Jul 19, 2006
Posts: 2
The correct options should be 'a' and 'e'.

since a system exception occured the transaction is marked for roll back. And since the System exception occured in bean B , it is discarded, but that does not Bean A will be discarded.
Rajesh Chande
Greenhorn

Joined: Jun 28, 2006
Posts: 18
Hello,

After rethinking on it, I change my opinion to "d" and "e".

it was a good one... ;-)

Regards,
Tiro.
Ugender Rekulampally
Ranch Hand

Joined: Nov 14, 2005
Posts: 130
E will be wrong option to pick ..since the exception is generated in TxA context (transaction A). In this case, the instance will be discarded. you dont want to keep the values even if you get a transaction exception in the same transaction context, or else it will keep your system in inconsitent state (may be dirty values).

The option A is wrong because, client get the exception(javax.ejb.EJBException) notice from transaction context A but it is upto the client to decide to continue the transaction or not. So the option B is correct.

The correct answers are B and D.



Thanks,
Ugender

[ July 19, 2006: Message edited by: Ugender Rekulampally ]
[ July 19, 2006: Message edited by: Ugender Rekulampally ]
Ashley Bideau
Ranch Hand

Joined: Apr 22, 2006
Posts: 40
Thanks guys for all the replies.
paresh vernekar
Ranch Hand

Joined: Jul 10, 2006
Posts: 52
Hi,
I have changed my opinion too.Ugender is right about B and D being the correct options

Regards,
Paresh Vernekar
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Transaction Question