title: How should I be configuring spring and hibernate so that my Integration Tests replicate properly the behaviour of the Web application?
body: <p>We have a web application based on NSpring 1.2 and NHibernate 2 and use HibernateTemplate.  The web application is configured to use <strong>OpenSessionInViewModule</strong>.</p>
  
  <p>In our integration tests however the hibernate session is marked as <strong>InitDeferredClose</strong> and for the most part this works fine for our  tests.  There are some service functions that work fine in the context of the web application but fail when called from a test harness.</p>
  
  <p>For example : I have one function that creates and updates a number of objects within a transaction.  The function is marked with the Transaction attribute but the test fails with the message : </p>
  
  <pre><code>Illegal attempt to associate a collection with two open sessions
  </code></pre>
  
  <p>When called from the web application the transaction completes successfully</p>
  
  <p>How should I be configuring spring and hibernate so that my Integration Tests replicate properly the functionnality of the Web application ?</p>