• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enthuware Wrong Answer

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ralph for your reply.


See this code, it is sending a message to Queue.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ralph, i got that post.

Please look here

https://coderanch.com/t/424618/EJB-Certification-SCBCD/certification/Enthuware
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic