• 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

EJB not rolling back database changes

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have an EJB method with transaction attribut 'Required'. We have multiple database updates in this method.To check whether the transaction handling is proper, we specifically threw an Exception after some table updates. This exception is caught and an EJBException is thrown later. Still the database changes are not rolling back. Please help me with this..

Could there be something at the DB level? We're using UDB 8.2

Thanks
Tom
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Required" means "if the client already has a transaction, participate in it, otherwise create a new transaction".

If you invoke a method on that bean and you didn't already have a transaction, it will create one. If you then throw an application exception, non-runtime exceptions don't cause a transaction failure. Control will flow out of the bean, and the transaction will commit normally. You either have to throw a runtime exception or mark the transaction for rollback manually. For performance reasons marking it manually is usually the way to go.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you throw EJBException, the transaction should have rolled back. What server are you using? If you get a JDBC connection from an incorrectly configured DataSource or directly from the JDBC driver, then it might not participate in the EJB container transaction.
 
Tom Raj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roger,
I'm using Websphere 5.1. and using UDB universal driver. I also think it could be something with the datasource. Do I have to create a reference to the datasource in the EJB deployment descriptor. I'm getting the connection outside the EJB and passing it to the EJB method.

Thanks
Tom
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you are expecting the rollback of an EJB to cause a rollback in a connection it had no part in obtaining from the container. Unless that connection was created in a second EJB, and both these EJBs are in the same transaction and are rolling back together, then the rollback of the EJB using the connection is irrelevant. As far as that EJB is concerned, the connection is just some kind of object passed as a method parameter, not something it is responsible for the lifecycle of.
 
Tom Raj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all, I figured out the issue. We were getting the connection outside the EJB. We moved the getConnection() method into the EJB and everything's working now.

Thanks
Tom.
 
reply
    Bookmark Topic Watch Topic
  • New Topic