• Post Reply Bookmark Topic Watch Topic
  • New Topic

Transaction not rolling back  RSS feed

 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Any ideas out there I could try?
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Application Server are you using?
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again

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'.

Many thanks for your reply.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What transaction attribute are you using for the EJB method?
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roger

do you mean this?
 
Sujith Kanaparthi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Sujith
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Come over here Sujith, big fella. You're getting a hug.

Works perfectly, many thanks.
 
Padma Lalwani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With container managed transactions, rollback should implictly occur when you throw RuntimeException
Make sure that not only the POJO but also the session bean throws back the RuntimeException.
Padma
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!