This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Enthuware Wrong Answer 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 "Enthuware Wrong Answer" Watch "Enthuware Wrong Answer" New topic
Author

Enthuware Wrong Answer

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
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?


1) Changes made by the bean code at line 24 will be committed.

2) Line 25 will throw an Exception

3) The message will be sent to the queue.

4) The message will be sent to the queue but the changes made to the database by the MDB will not be committed.

5) The container will resend the message to the queue.

6) Neither the message is sent nor any database changes get committed.


the correct answer given is 6.

Explanation- 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.

the correct answer is 1.

Question say's, "if the MDB associated with the queue Q1 rolls back the transaction but does not throw any exception". So the MDB is rollbacking the transaction. it should have no impact on the MyBean code which is sending them the message. So the changes done by MyBean code, should be committed.

Explanation give's the hint, that MyBean transaction has been rolled back.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
It's clear that myBeanMethod() neither sends a message (see core spec 13.3.5) nor commits the changes.
So the only possible answer is 6).

Note: The question doesn't state that the message that causes the MDB to rollback a transaction actually
was send by MyBean. It could also be send by another component that is associated with Q1, too.

SCJP 5 (98%) - SCBCD 5 (98%)
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Thanks Ralph for your reply.


See this code, it is sending a message to Queue.
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
See this code, it is sending a message to Queue

Yes, but in an transactional way. That means the message won't be send physically until the
messaging system receives a commit. That's similar to

entityManager.persist(customer); // persists a customer

The persist won't be written to the dababase until the db receives a commit.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
OK Ralph, i got some hint from you. Thanks for explaining.

I have also such a similar question in Enthuware, which has almost similar answer as 1.

Whenever i will encounter, i will let you know.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Hey Ralph, i got that post.

Please look here

http://www.coderanch.com/t/424618/EJB-Certification-SCBCD/certification/Enthuware
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Hi Amandeep,

thanks for looking for the question. See the difference:

In question 1 above the client's transaction is rolled back. Therefore the message won't be
send by the client nor will the client's db be updated (just what enthuware says).

In question 2 in the link, the client's transaction commits. After this commit, the message will
be send to the queue. Since the client's transaction has already commited it isn't influenced by
the MDB's behavoir.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Ralph Jaus wrote:Hi Amandeep,

thanks for looking for the question. See the difference:

In question 1 above the client's transaction is rolled back. Therefore the message won't be
send by the client nor will the client's db be updated (just what enthuware says).

In question 2 in the link, the client's transaction commits. After this commit, the message will
be send to the queue. Since the client's transaction has already commited it isn't influenced by
the MDB's behavoir.


Thanks Ralph for your reply...
i didn't understand how you came to this conclusion-

Question- 1 says

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?


Question- 2 says


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?
 
GeeCON Prague 2014
 
subject: Enthuware Wrong Answer