Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Doubt in Transaction

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Balaji Anand
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic