Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Mock Question HFEJB page 520. Q3.

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

Statement C in this question states for CMT that:

If an onMessage() method returns before committing a transaction the container will throw an exception.



The answer is false. For BMT beans, this statement would be true. For CMT beans the container is responsible for committing transactions, so how could this situation, namely returning without committing, arise? Are we to assume a container rollback has taken place?

I am confused by the statement, would some knowledgeable soul please clarify it?

regards and thanks,
Simon
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returning without committing can arise if the method throws a system exception (like EJBException or ay other runtime exception).
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the method throws a system exception, then the Container will throw either an EJBException (to a local client) or a RemoteException (to a remote client).

The Container will not throw an exception if:
The bean throws an application exception (which the Container just passes to the client).

The setRollbackOnly() method is invoked. In this case, the Container will ensure that the transaction is rolled back.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the option is saying onMessage() method, are we not talking about MDB?? In that contest there is no client
My understanding is
no client(MDB)+CMT+ something wrong(sys exception) == container manages things(either riollback or whatever)
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite right, I take back half what I wrote. As there is no client, I'd think that only setRollbackOnly() applies for MDBs.

It's pointless to throw anything other than EJBException from an MDB.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gentlemen,

thanks for your answers, but the situation is still not clear. The answer to the question tells us that if the onMessage method returns before committing a transaction, then the container does not throw an exception. Roger has said that if the bean throws a system exception, then the container will throw either a RemoteException or an EJBException. He then discusses the circumstances under which the container does NOT throw an exception and it was concluded, finally, that if the setRollback method is called in the bean code, the container will not throw an exception. This is all true, but we have missed the point.

The question asks us which statements are true about CMT and the following is not marked, meaning it is false.

If an onMessage() method returns before committing a transaction the container will throw an exception



but how can this be? We have said that the container will throw an exception unless we call setRollbackOnly. But the statement says nothing about setRollbackOnly. So, is the answer wrong?

regards
Simon
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I reckon that this question is typical of what you will get in the exam, in that you are given a set of circumstances and then have to figure something out. In this case, you have to figure out that setRollbackOnly() had to be called in order to prevent a commit.

After all, it would be too easy to ask a question along the lines of: Does setRollbackOnly() cause the Container to prevent a commit and not throw an exception, answer true or false.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is a trick question. You never commit your transactions in CMT. You always return before the transaction is committed. So obviously it has to be false.
 
Suman Sarker
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roger,
In one of ur previous replies, u said

The Container will not throw an exception if:
The setRollbackOnly() method is invoked. In this case, the Container will ensure that the transaction is rolled back.


But the EJB spec (p377, table 17) says Container will handle system exceptions by logging the exception, marking the trasaction for rollback (if the tx attribute is Required) and discarding the bean instance.

My understanding is, in case of system exception, the container will never throw it and always handle it by itself.

If that is so, then the book is right in saying that the following statement


If an onMessage() method returns before committing a transaction the container will throw an exception


is false. Because if an onMessage() method returns before committing, then we can take it for granted that a system exception occured. And in case of system exception, the container will not throw it (who will it throw it to?) but handle it by itself.

Regards
Suman
[ May 23, 2004: Message edited by: Suman Sarker ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, I kept forgetting that the Container will only throw an exception to the client upon receipt of a system exception where there is a client. Obviously, this only applies to session and entity beans, but never message-driven beans.

So, in summary, the Container will not commit the transaction and will not throw an exception if it receives a system exception or if setRollbackOnly() is invoked.
 
This will take every ounce of my mental strength! All for a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic