• 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

@Transactional(rollbackFor=Exception.class) not rolling back the data

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i am trying to learn spring transaction. i am using jdbcTemplate for setting up connection but @Transactional(rollbackFor=Exception.class) does not seem working as it is not rolling back the data.
to give an overview i have written two methods. one method will reduce some amount from one row and other method will increase the amount in other row. i am calling both the methods from one single method and annotated that single method with @Transactional(rollbackFor=Exception.class) as mentioned below.

i am already having accountDao object so please don't worry about that.



now i am calling creditInToAccount method first and debitFromFromAccount next to it. in my debitFromFromAccount method i am throwing an Exception which should actually rollback the result of query executed in creditInToAccount but rolling back of creditInToAccount is not happening.
i check javaranch for the same and came across below mentioned thread
https://coderanch.com/t/572768/Spring/Rollback-not-working-Transactional#2605624
but in this link it is mentioned to set autocommit as false but i dont know how to do the same when using jdbcTemplate.

below is the snippet of xml that i am using for configuration



please help.

thanks,
pratz
 
prateek sharmaa
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone has any idea about this? Please help.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which class is the transferMoney() money in? Is this class under spring control? How are you testing (Junits?, A main class? A web app?)?
 
prateek sharmaa
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sam,
thanks for the reply. your doubt was right. my TransferService class(in which transferMoney() method was there) was not under control of Spring. i have defined TransferService class as @Service and now its working

thanks,
pratz
reply
    Bookmark Topic Watch Topic
  • New Topic