*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes mock question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "mock question" Watch "mock question" New topic
Author

mock question

Mihai Alexe
Greenhorn

Joined: Apr 13, 2005
Posts: 19
Here's a sample question from a JDiscuss mock exam:

Question No: 28 (Question ID: 1940) Exceptions : Real Brainer

Consider the following code occuring in a MyBean code. It updates the database and sends a message to a queue named Q1. The message driven bean (not same as MyBean) associated with the queue requires a transaction and updates the database upon receiving a message.
Assuming that all the variables are properly defined and used, what will happen if the MDB associated with the queue Q1 rolls back the transaction but does not throw any exception?



Select 1 correct option.

  • Changes made by the bean code at line 24 will be committed.
  • Line 25 will throw an Exception
  • The message will be sent to the queue.
  • The message will be sent to the queue but the changes made to the database by the MDB will not be committed.
  • The container will resend the message to the queue.
  • Neither the message is sent nor any database changes get committed.


  • The mock exam marks the last option as correct, while I assumed it was the 1st. Unfortunately, no other explanations are given. So please clear this up for me...it's probably somtehing with the message send() and the MDB rolling back its tx that causes the client transaction to roll back, but I'm not clear what and why - my guess is that the client code and the MDB's onMessage() run in separate transactions since the MDB requires a TX and the client's TX cannot be propagated to it [the client never "sees" the bean].

    Thanks a bunch!
    [ September 09, 2005: Message edited by: Mihai Alexe ]

    SCJP for Java 1.4<br />SCBCD for J2EE 1.3
    Mihai Alexe
    Greenhorn

    Joined: Apr 13, 2005
    Posts: 19
    Hm,... it would appear that they posted an explanation - but not too clear - at least for me


    In this case, the sending of the message is a part of MyBean's transaction. Therefore, if it rollsback the transaction, the message will not be sent.
    The message will not be redelivered because it was never sent!
    The database changes will not be committed because the transaction was rolled back.


    Any comments on this?
    amol deshpande
    Ranch Hand

    Joined: Sep 05, 2003
    Posts: 162
    Hello guys,
    The point is,
    The message to a Queue is actully not sent unless the contained transaction is committed. Since the tx in context is rollbacked, the actual sending of message to a queue never takes place.

    I hope there is no doubt as to the fact that db is not updated...simply coz tx is rollbacked.
    Amol
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: mock question