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
posted 13 years ago
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.
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