aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes MDB throw system exception 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 "MDB throw system exception" Watch "MDB throw system exception" New topic
Author

MDB throw system exception

Jason Hunt
Ranch Hand

Joined: Sep 09, 2002
Posts: 51
From ejb spec:

--------------------------------------------
If a message-driven bean instance starts a transaction in the onMessage method, it must commit the transaction before the onMessage method returns. The Container must detect the case in which a transaction was started, but not completed, in the onMessage method, and handle it as follows:
� Log this as an application error to alert the system administrator.
� Roll back the started transaction.
� Discard the instance of the message-driven bean.
-------------------------------------------------

So Does this means that if a BMT message driven bean throw a system exception, the container will roll back the transaction.


SCJP, SCWCD, SCBCD, SCDJWS, OCA9i,<br />IBM Certified WAS5.0 Admin<br />IBM Certified Solution Developer - WebSphere Studio 5.0<br />IBM Certified Solution Developer - XML and related Technologies
Sandesh Tathare
Ranch Hand

Joined: Jun 22, 2003
Posts: 82


From ejb spec:

--------------------------------------------
If a message-driven bean instance starts a transaction in the onMessage method, it must commit the transaction before the onMessage method returns. The Container must detect the case in which a transaction was started, but not completed, in the onMessage method, and handle it as follows:
� Log this as an application error to alert the system administrator.
� Roll back the started transaction.
� Discard the instance of the message-driven bean.
-------------------------------------------------

So Does this means that if a BMT message driven bean throw a system exception, the container will roll back the transaction.



Container will rollback transaction when bean instance throws a system (non-application) excetion.

Please refer to what Specs says on page 374:

Bean Provider can rely on the Container to perform the following tasks when catching a non-application exception:
� The transaction in which the bean method participated will be rolled back.

Does that answer your question?


Regards,<br />Sandesh<br />(SCJCP, SCWCD, SCBCD - 99%, OCP-1)<br /> <br />Either find a way or create one.
Jason Hunt
Ranch Hand

Joined: Sep 09, 2002
Posts: 51
thanks, and throw system exception doesn't mean there is transaction to be rolledback, am i right ?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
You have to look at Table 18 on page 378 of the spec. When a BMT message-driven bean throws a system exception the container must take the following actions:
  • Log the exception or error.
  • Mark for rollback a transaction that has been started, but not yet completed, by the instance.
  • Discard instance.


  • Remember that in BMT beans the Bean provider is responsible for demarcating the transactions, and thus, the container does not get to start and or commit the transactions. However, it must call setRollbackOnly on user transactions that have not yet been completed in case a system exception is thrown.


    SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
    [Blog] [Blogroll] [My Reviews] My Linked In
    Jason Hunt
    Ranch Hand

    Joined: Sep 09, 2002
    Posts: 51
    yes, the spec said that. but I just don't understand, BMT MDB has no client view, if mdb call some entity bean and make some changes, and it throw out the system exception, the container just mark the tx for rollback, then who will do the rollback work, if nobody rollback the transaction, then why mark for rollback. The container will discard the instance sooner or later.
    Roger Chung-Wee
    Ranch Hand

    Joined: Sep 29, 2002
    Posts: 1683
    Typically, the container instructs the transaction manager to mark the transaction for rollback. The tx is then rolled back. This is needed even for a BMT message-driven bean which has started a tx, because database integrity must be maintained in the event of a system exception being thrown by the bean.


    SCJP 1.4, SCWCD 1.3, SCBCD 1.3
    Giju George
    Ranch Hand

    Joined: Jun 08, 2004
    Posts: 333
    So, does this means, "container marks the transaction for rollback" and "container rollback the container-started transaction" are the same.. ???
    If so, then why does the contaienr just marks it for rollback rather that doing the rollback itself ???


    SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCEA
     
    Consider Paul's rocket mass heater.
     
    subject: MDB throw system exception