Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

HFEJB - pag 564 - exception question

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Neetika
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic