Win a copy of Microservices Testing (Live Project) this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Transaction not rolling back

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Application Server are you using?
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roger

do you mean this?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Come over here Sujith, big fella. You're getting a hug.

Works perfectly, many thanks.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic