wood burning stoves 2.0*
The moose likes Spring and the fly likes @Transactional(rollbackFor=Exception.class) not rolling back the data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@Transactional(rollbackFor=Exception.class) not rolling back the data" Watch "@Transactional(rollbackFor=Exception.class) not rolling back the data" New topic
Author

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

prateek sharmaa
Ranch Hand

Joined: May 15, 2010
Posts: 38
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

Joined: May 15, 2010
Posts: 38
Does anyone has any idea about this? Please help.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

which class is the transferMoney() money in? Is this class under spring control? How are you testing (Junits?, A main class? A web app?)?


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
prateek sharmaa
Ranch Hand

Joined: May 15, 2010
Posts: 38
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @Transactional(rollbackFor=Exception.class) not rolling back the data