wood burning stoves*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubt in Transaction 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 "Doubt in Transaction " Watch "Doubt in Transaction " New topic
Author

Doubt in Transaction

Shanmugam Karthikeyan
Ranch Hand

Joined: Aug 02, 2002
Posts: 58
Hi,

Can anyone let me know the answer for this question.

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?

1. The client's transaction will be marked for roll back.
2. The client will get a javax.ejb.EJBException but it can continue with the same transaction.
3. The client will get a javax.ejb.TransactionRolledbackLocalException
4. The bean B instance will be discarded.
5. mA() will get a javax.ejb.TransactionRolledbackLocalException
6. The bean A instance will NOT be discarded.
7. Changes made to the database by mA(), will be commited.


SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3
Ugender Rekulampally
Ranch Hand

Joined: Nov 14, 2005
Posts: 130
Hi Karthikeyan,
method mB() runs in TxA according to the problem description. So now, for some reason, this method is throwing 'System' Exception:

So, by default, the transaction will be rolled back.
Bean B instance will die.

So based on above points, we can say, the answers are : 1, 4, 5.

But I am not sure wether client will get the Exception message (javax.ejb.TransactionRolledbackLocalException) Since it is a system exception. can any one explain more on this option?

And I am assuming Bean 'A' won't be discarded but mA() just gets the messageexception of javax.ejb.TransactionRolledbackLocalException.

Thanks,
Ugender
Balaji Anand
Ranch Hand

Joined: Nov 03, 2004
Posts: 146
The answers are

2. the client will get an EJBException
4. bean B will be discarded


What is not true and why?
1. the clients transaction may or may not be rolledback (page 376 table 15 of the spec)
3. the clients transaction is not the clients transaction so it will not get this exception unless its transaction is rolled back.

what I think may be true

5. mA() will get a javax.ejb.TransactionRolledbackLocalException
6. The bean A instance will NOT be discarded.

and false because 5 is true
7. Changes made to the database by mA(), will be commited.

so finally
true :- 2,4,5,6
Shanmugam Karthikeyan
Ranch Hand

Joined: Aug 02, 2002
Posts: 58
Hi,

Thanks for your answer.

Before asking my doubt i want to make sure that whether i have understood the question in a correct way.

In this case

"A client having a transaction context calls a method mA() on bean A, which in turns calls a method mB() on Bean B"

This means client having a trans TxA called a method mA() on bean A, since bean A method is having tran attribute as requirednew it will suspend TxA and start a new Transaction TxB, which in turns calls a method mB() on Bean B which is having tran attr as supports.Since it is having supports it will continue with the transaction TxB.

So here both Bean A and the bean B methods are invoked with transaction TxB.

Once both the method completes the container will resume the transaction TxA.

Pls let me know whether i am right in understanding this question.

If iam right, if Bean B throws a system exception, the Transaction TxB will be rollbacked and bean B will be discarded.Since Bean A calls Bean B, it will get javax.ejb.TransactionRolledbackLocalException.

Since TransactionRolledbackLocalException is a system exception the container will throw EJBException to the local Client.

Is this the reason why your answer is correct.
Ugender Rekulampally
Ranch Hand

Joined: Nov 14, 2005
Posts: 130
Srividhya,
thanks for the detailed reply...but I still have some points to raise..

We know entire transaction runs in TxA
mA()
{
mB(){ }

}

So mB() throwing a System exception not an Application Exception so that means mA() has a System exception in its processing so, obviously transaction will be rolled back.
and the option 2 says "The client will get a javax.ejb.EJBException but it can continue with the same transaction"

In my view, transaction won't continue so option 2 is wrong. and option 1 is right "The client's transaction will be marked for roll back."

and I agree with you on option 6.

finally, I am thinking these are correct answers 1,4,5, 6..

Correct me if any of my assumptions are wrong.

Thanks,
Ugender
Michael Valentino
Ranch Hand

Joined: Nov 01, 2005
Posts: 96
Ugender,

I agree with most of your answers, except option 1. Since Bean A's method mA() is marked "RequiresNew" this transaction will roll back. This does not affect the Client's transaction (client to Bean A). I don't agree with 6, because if client A gets a TransactionRolledBackLocalException, a runtime exception, Bean A will be discarded. Therefore I'd switch options 1 and 2, and say that the correct answers are 2,4,5
[ June 06, 2006: Message edited by: Michael Valentino ]

SCJP 1.4, SCWCD J2EE 1.4, SCJD J2SE 1.5, SCBCD J2EE 1.3, SCDJWS (In Progress)
Balaji Anand
Ranch Hand

Joined: Nov 03, 2004
Posts: 146
hi,

I made a mistake.

1. False - The client's transaction will be marked for roll back.
2. False - The client will get a javax.ejb.EJBException but it can continue with the same transaction.
3. False - The client will get a javax.ejb.TransactionRolledbackLocalException
4. True - The bean B instance will be discarded.
5. True - mA() will get a javax.ejb.TransactionRolledbackLocalException
6. False -The bean A instance will NOT be discarded.
7. False - Changes made to the database by mA(), will be commited.

Reasons

1,2,3 page - page 376 table 15 of the spec - here it says... the clients transaction may or may not be marked for rollback and the client will get an EJBException. I disagree with valentino on this since the spec only says the clients tran may or may not be marked for rollback even thought the bean uses its own tran.

4,5- we know why

6- I agree with Valentino, since TransactionRolledbackLocalException is a System Exception bean A will also be discarded

7- the tran will not be commited.
Michael Valentino
Ranch Hand

Joined: Nov 01, 2005
Posts: 96
So just out of curiosity, what are the correct answers given by the source of the question? If my thinking was flawed (which it definitely may be) I'd like to at least find out why my choices were incorrect before I go take that exam
Michael Valentino
Ranch Hand

Joined: Nov 01, 2005
Posts: 96
Ah interesting, I found this question on the JDiscuss Mock Exam. The answers they said were correct were 2,4,5. But reading the previous post, I'm not 100% sure that answer 2 is correct. As mentioned, the spec says that in this situation the client transaction "may or may not be rolled back". This is extremely vague, especially for a specification. In addition, I don't see how the client's transaction could be rolled back since it must be suspended to execute mA(). Do you all agree with that? Any EJB gurus (possibly exam Writers!) listening on this thread?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in Transaction
 
Similar Threads
Mock question: Tx
When is a Bean Discarded?
Does JBoss behave so much different from specs?
Transaction Question
sample Question