title: JTA Callbacks in Spring
body: <p>Is it possible to register some kind of callback with a JTA transaction in a Spring application?</p>
  
  <p>I've got some mock services that are standing in for remote services that belong to another application that's normally accessed using Spring's <code>HttpInvoker</code>. These mock services model data in-memory in a trivial fashion using <code>Map</code>s and the like.</p>
  
  <p>The Unit tests don't necessarily know which of these services might get used; the service the test case is targetting might use them behind the scenes.</p>
  
  <p>The unit tests are transactional, and Spring's <code>SpringJUnit4ClassRunner</code> will rollback the transaction after each test, meaning that the state fo our unit test database is preserved between tests.</p>
  
  <p>How can I rollback the state of this custom in-memory service implementation? If there was a way of finding out if there's a transaction currently going on, then I was hoping there'd be a way of registering a callback with the <code>TransactionManager</code> to be executed before the transaction is completed.</p>