Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

MDB tx rollback question

 
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?
 
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 ]
 
Ranch Hand
Posts: 211
  • 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.

 
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,
     
    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 ]
     
    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!
     
    Evildoers! Eat my justice! And this tiny ad's justice too!
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic