Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MDB tx rollback question

 
Jason Hunt
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I did the ejb mock test, there is sth I don't understand.

The test said the following statement regarding message-driven bean exception handling is false:

If a system exception is thrown by a method, the transaction is always rolled back by the container

The explanation is:
----------------------------------------------------
A transaction is not rolled backed by the container as a result of a system exception thrown when the transaction runs with an unspecified transaction context and also when a bean is declared with bean-managed transaction demaraction.
------------------------------------------------------

I agree that if the MDB in an unspecified transaction context, then there would be no rollback, but with BMT throw system exception, the container should rollback the tx, right?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the whole idea with bean-managed transactions --- the container's hands are tied!
 
Jason Hunt
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but it is the system exception, bean won't handle it and who will log the exception, rollback the exception and kill the bean ? it should be Container, isn't it ?
[ July 16, 2004: Message edited by: Jason Hunt ]
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jason Hunt:
but it is the system exception, bean won't handle it and who will log the exception, rollback the exception and kill the bean ? it should be Container, isn't it ?

[ July 16, 2004: Message edited by: Jason Hunt ]


In a BMT scenario, if the bean encounters a system exception, the current transaction will be NOT be rolled back(unless otherwise the bean handles the Exception and calls UserTransaction.rollback()). However, the container may choose to discard the instance or move it to the pool.

 
Nadeem Awad
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Jason,
In EJB 2.1 Specs, Section 18.3.3, Table 19, Page 404, it says that when an MDB with Bean-Managed Transaction demarcation throws a System exception the container will do the following:
  • Log the exception or error.
  • Mark for rollback a transaction that has been started, but not yet completed, by the instance.
  • Discard instance.
  • Throw EJBException that wraps the original exception to resource adapter.



  • Best regards,
     
    Jim Janssens
    Ranch Hand
    Posts: 210
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Like Nadeem said, its indeed in the spec. I think you are correct.
    For ejb2.0 spec see: 18.3.2 table 18.

    --EDIT--

    Is it possible to post the complete question with all the possible answers ?
    [ July 24, 2005: Message edited by: Koen Serneels ]
     
    Roger Chung-Wee
    Ranch Hand
    Posts: 1683
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    That's the whole idea with bean-managed transactions --- the container's hands are tied!

    Actually, no. BMT means that the developer demarcates the transaction boundaries. But if a system exception is thrown from a BMT bean method, the Container will step in an rollback the transaction. Remember, the Container is the boss!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic