• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB - pag 564 - exception question

 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks!!!

As far the question number 5, why isn't the option A correct as well since it also guarantees that there will be a TX actives?

On the page 552, i can see these:

"The container throws this to the caller when the container can't commit the transaction and the caller invoked the method within an existing transaction context. But the container will not throws this exception if the failure to commit is because the bean explicitly called setRollBackOnly() method!".

So i cannot see here it means that we really need to have that by using the "mandatory" attribute.

Tks guys!!!
 
neetika sharma
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question clearly asks"In which case will the container always throws a TransactionRolledBackException"

"The container throws this to the caller when the container can't commit the transaction and the caller invoked the method within an existing transaction context"

"Requires new" attribute does not signifies an already existing transaction context as in this case, the method will always run with a new transaction not with an existing transaction , which is required condition for this exception.

In case of "RequiresNew" attribute, if the method is called with an existing transaction context, the caller's transaction is suspended until the method completes(refer pageno: 494).

Mandatory means "Requires Existing".
 
Napu Sun
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If use "RequireNew", then the method always on the new transaction, it cannot prove the method's caller is in an existing transaction. So container will not already throw TransactionRolledbackException. When caller is in the transaction, the method with "RequireNew" will throw TransactionRolledbackException. But when caller is not in the transaction, container will not throw.

Here, I got a question:
when caller is not in the transaction, then the method with "RequireNew" throws a system exception, what exception the container will finally throw?
I think container will throw RemoteException for remote client, EJBException for local client.
 
neetika sharma
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah you are correct,

when Bean method runs in the context of a transaction that the Container started immediately, i.e marked with attribute "RequireNew" and throws a system exception then the container will throw RemoteException to REMOTE client/ EJBException to LOCAL client.
 
Napu Sun
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Neetika
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic