Forums Register Login

EJB not rolling back database changes

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
"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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1416 times.
Similar Threads
J2EE transactions - stateless beans (CMT)
OracleConnectionProxy is closed.
Jboss related transaction problem
transaction when multiple database connections are open
Using commit and rollback
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 00:42:27.