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.
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?
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.
"How are you configuring your datasource is autocommit set to false? " . No ,is it required to set!
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.
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
the code is in my personal PC.so i cannot post it now.
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
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.