Search code examples
springspring-transactionsdbunit

Why my dataset is not committed to my Oracle database using DBUnit and @DatabaseSetup annotation


I'm new to spring and DbUnit. I configured my DBUnitDatabaseConnection correct. I'm using the @DatabaseSetup(..) to insert a dataset. when requesting these data over my auto wired DAO-object, i am finding all my data. All is fine, but when i want to access the data over a REST request, i can't find any data, because they are not committed and saved to my oracle database. My data are committed after my test finished. How can i achieve that my data getting committed before my test method starts? Clearing and flushing my session doesn't work either.

UPDATE: These annotations are used in my testclass:

  • @DiertiesContext
  • @Transactional
  • @RunWith(SpringJUnit4ClassRunner.class)
  • @DbUnitConfiguration(databaseConnection = "dbConnection")
  • @ContextConfiguration(loader=AnnotationConfigContextLoader.class, classes=MyBeanConfig.class)
  • @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionDbUnitTestExecutionListener.class})

my dbConnection Bean has set "defaultAutoCommit" to "true", and "dataTypeFactory" to "Oracle10DataTypeFactory". My java-based configuration also enables TransactionManagement.


Solution

  • Instead of clearing and flushing the session, i committed the current transaction. That's working.