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.

Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Facebook
  • Twitter
  • LinkedIn
  • email
  • DZone
  • Slashdot
  • Reddit
  • Google Bookmarks
  • Digg
  • StumbleUpon
  • del.icio.us
This entry was posted in DB, Spring Framework, Testing and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">