• 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

transaction rollback

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

i have method




Now what i want is even if updateMinSalary() succeds and i am purposefully throwing NullPointer exception from updateMaxSalary() and expecting data should not be updated in the database and whole updateSalary method should be rolled back, but the updateMinSalary() method inserting the data.how to prevent it.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you configured annotation and aop autoproxy tags in xml file ? I am suspecting annotations are not been called at all.

Thanks
 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i used only <tx:annotation-driven/> tag only
 
Manish Sridharan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to define the transaction manager for your annotation tags. Something like this.Thanks,
 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi manish it is my mistake to not to provide complete details in begining post.

as mentioned in your reply i defined datasource , transaction manager and <tx:annotation-driven /> tag and jdbc template to update Database from begining . Inspite of this the problem occured.

You please use the same configuration and code (within this use jdbc template for database updation) i gave to reproduce the problem.
 
Manish Sridharan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you set transaction manager in I would appreciate if you turned on logging for spring jars and attached the spring source to it and then you can see where does it getting failed.

Thanks
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all you should never throw a null pointer exception. Create your own ApplicationService runtime exception if you need to, but throwing null pointer is bad code smell

Secondly you don't need the 'Rollback for ' as @Transactional will roll back when it encounters any runtime exception by default. On top of that from what you are explaining I don't think you need the propagation tags either spring will wrap the inner transactions into the outer ones and they should roll back together so I would get rid of that to.

How are you configuring your datasource is autocommit set to false?

Thanks,
 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi manish,
By default spring looks for transaction manager with name transactionManager . so i have not explicitly added attribute transaction-manager to <tx:annotation-driven /> . I tried adding but no change in result.

Hi Bill,
"How are you configuring your datasource is autocommit set to false? " . No ,is it required to set!
 
Manish Sridharan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I too expected the transaction manager should automatically get picked up by spring but I too have similar issues. I need to attached transaction manager to tx:annonation tag to make it work. I was using spring 3.1.1 jars.
I guess, first thing you need to confirm whether transaction manager is getting invoked or not and then perhaps you can check what is causing failure in rollback.

As Bill point it out correctly, if you are writing your database connection code then you need to set autocommit to false in your code before you do any transaction. You can refer to this URL for more information.

Thanks
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kish,

It might be helpful if you could post the relevant pieces of your spring configuration file.
 
kish kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi manish,
I am not using connection object anywhere since the main purpose of jdbcTemplate object itself is to avoid the boilerplate code like opening connection ,closing connection etc.
i have seen the URL you have given where connection object is used. I guess there must be a way to solve it without calling connection object

Hi Bill,
the code is in my personal PC.so i cannot post it now.


Thanks
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Not related but this post was really helpful. None of my transaction were getting rolled back even though I had used the @Transactional attribute. It seems I had missed the following two attributes in my configuration file

And I had to add the namespace in



reply
    Bookmark Topic Watch Topic
  • New Topic