views:

21

answers:

0

I'm using Spring Test and JUnit to run DAO integration tests. The test class is annotated as follows:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/testPersist-applicationContext.xml" })
@Transactional

I use the @BeforeTransaction annotation on a method to insert some test data -- that I would expect to be there for every test method. However the data is only present for the first test method and is gone after that first test method is rolledback.

I am using JPA/Hibernate as the ORM and Atomikos as a stand alone transaction manager so these integration tests would run outside an app server.

As a test -- I created a simple JDBC data source (thinking that it wouldn't participate in any transaction) and used it from within the @BeforeTransaction method to insert the test data. The trick worked and the test data remained throughout the test case and every test method passed.

However, I should not have to do that, and am looking hard for the underlying reason why data inserted from within a method annotated with @BeforeTransaction would be rollbacked along with the first test method.