Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused by Ets's 2 questions

 
Tang Yue
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a CMT message-driven bean with REQUIRED attribute rolls back a transaction but no exception thrown, will the message be redelivered?
The answers of the 2 questions seem to be contradictory.

In Enthuware Test 4 Question no.49:
"
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.

11. public void myBeanMethod()
12. {
...
21. UserTransaction ut = ejbContext.getUserTransaction();
22. ut.begin();
23. queueSender.send(message); //sends a message to a queue Q1.
24. stmt.executeUpdate(query1);
25. ut.rollback();
...
30. }

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?
"

The correct answer is "Neither the message is sent nor any database changes get committed."

The explanation says
"
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!
"

HOWEVER, in Test 4 Question No.51, the correct answer is "The transaction started by the MDB is rolledback and JMS Message redelivery semantics will apply."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic