Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
prateek sharmaa
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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
http://www.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
  • Quote
  • Report post to moderator
Does anyone has any idea about this? Please help.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic