title: How to propagate Spring transaction to another thread?
body: <p>Perhaps, I am doing something wrong, but I can't find a good way out for the following situation.</p>
  
  <p>I would like to unit test a service that uses <a href="http://static.springsource.org/spring-batch/" rel="noreferrer">Spring Batch</a> underneath to execute jobs. The jobs are executed via pre-configured <code>AsyncTaskExecutor</code> in separate threads. In my unit test I would like to:</p>
  
  <ol>
  <li>Create few domain objects and persist them via DAO</li>
  <li>Invoke the service method to launch the job</li>
  <li>Wait until the job is completed</li>
  <li>Use DAO to retrieve domain objects and check their state</li>
  </ol>
  
  <p>Obviously, all above should be executed within one transaction, but unfortunately, <a href="http://forum.springsource.org/showthread.php?t=72845#post250054" rel="noreferrer">transactions are not propagated to new threads</a> (I understand the rationale behind this).</p>
  
  <p>Ideas that came to my mind:</p>
  
  <ul>
  <li>Commit the transaction#1 after step (1). Is not good, as the DB state should be rolled back after the unit test.</li>
  <li>Use <code>Isolation.READ_UNCOMMITTED</code> in job configuration. But this requires two different configurations for test and for production.</li>
  </ul>