Spring and Transactions

I’ve been taking a legacy codebase, putting testing in place and refactoring. For DB access I retrofitted the persistence classes to be injected via Spring with a DataSource instead of looking them up via JNDI. IN my Spring context I defined a PlatformTransactionManager.

Then I refer to it in the the test case class.

Sure enough the console blathered on about starting and rolling back the transaction. The problem is, it wasn’t. It was just saying it did.

How do I know? I checked.

So what was the problem?

I was doing this like every other J(2)EE programmer.

But with Spring you need to do this instead to associate the transaction thread with the datasource.

Then it worked.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.