I have a stateless session bean that invokes a pojo, which ultimatley interacts with a Sql Server database.
In the invoked transaction, an insert statement is executed, immediately followed by a select statement; both these queries are passed through the same connection.
If the second query fails, the first query is still persisted to the db. I've tried catching the SQLException and throw a runtime exception, no difference; I've tried toggling the <transastion-type> between 'Bean' and 'Container' -no difference; I've attempted to set the container transaction type to 'Required', nothing!
I'm using IBM WebSphere (5.1.2), but I've already posted this question on that forum, with no responses - I was hoping this might be the place to get some info.
Anyway, this issue has brought up a discussion I'm having with a colleague. I had previously used Weblogic, and I'm certain that in the event of an exception being encountered within the application, unless told otherwise through exception handling, the Application Server should roll back the entire transaction, regardless of how many database updates have been enacted within the scope of that transaction. Consequently, your datamodel is returned to the state it was in prior to the failed transaction having been invoked. Am I right?
Just a thought - I'm invoking the bean services through the local interface - this shouldn't have any effect, should it?
Would the JDBC driver have any impact on this? I'm using the 'Microsoft JDBC driver for MSSQLServer 2000'.
Hi Alana, If you are using Container Managed Transactions(CMT) and set the container transaction type to 'Required' then call setRollBackOnly()(javax.ejb.EJBContext contains this method) in the block where you want to rollback the transaction whenever an unexpected situation raises.Hope this may help you.