title: Set Hibernate session's flush mode in Spring
body: <p>I am writing integration tests and in one test method I'd like to write some data to DB and then read it. </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = {"classpath:applicationContext.xml"})
  @TransactionConfiguration()
  @Transactional
  public class SimpleIntegrationTest {
  
      @Resource
      private DummyDAO dummyDAO;
  
      /**
       * Tries to store {@link com.example.server.entity.DummyEntity}.
       */
      @Test
      public void testPersistTestEntity() {
          int countBefore = dummyDAO.findAll().size();
          DummyEntity dummyEntity = new DummyEntity();
          dummyDAO.makePersistent(dummyEntity);
  
          //HERE SHOULD COME SESSION.FLUSH()
  
          int countAfter = dummyDAO.findAll().size();
  
          assertEquals(countBefore + 1, countAfter);
      }
  }
  </code></pre>
  
  <p>As you can see between storing and reading data, the session should be flushed because the default <code>FushMode</code> is <code>AUTO</code> thus no data can be actually stored in DB.</p>
  
  <p><strong>Question:</strong> Can I some how set <code>FlushMode</code> to <code>ALWAYS</code> in session factory or somewhere else to avoid repeating <code>session.flush()</code> call?</p>
  
  <p>All DB calls in DAO goes with <code>HibernateTemplate</code> instance.</p>
  
  <p>Thanks in advance.</p>