I write integration tests, and in one testing method I would like to write some data in the database, and then read them.
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) @TransactionConfiguration() @Transactional public class SimpleIntegrationTest { @Resource private DummyDAO dummyDAO; @Test public void testPersistTestEntity() { int countBefore = dummyDAO.findAll().size(); DummyEntity dummyEntity = new DummyEntity(); dummyDAO.makePersistent(dummyEntity);
As you can see between saving and reading data, the session should be reset, because by default FushMode is AUTO , therefore data cannot be actually stored in the database.
Question: Can I specify how to set FlushMode to ALWAYS in a factory session or somewhere else to avoid repeating the call to session.flush() ?
All DB calls in the DAO come with an instance of HibernateTemplate .
Thanks in advance.
spring hibernate spring-3
glaz666
source share