Spring and JUnit annotated tests: creating fixtures in separate transactions

Posted by Francois on Stack Overflow See other posts from Stack Overflow or by Francois
Published on 2010-05-26T16:08:43Z Indexed on 2010/05/26 16:11 UTC
Read the original article Hit count: 239

Filed under:
|
|
|

I am testing my Hibernate DAOs with Spring and JUnit.

I would like each test method to start with a pre-populated DB, i.e. the Java objects have been saved in the DB, in a Hibernate transaction that has already been committed. How can I do this?

With @After and @Before, methods execute in the same Hibernate transaction as the methods decorated with @Test and @Transactional (first level cache may not be flushed by the time the real test method starts). @BeforeTransaction and @AfterTransaction apparently cannot work with Hibernate because they don't create transactions even if the method is annotated with @Transactional in addition to @Before/AfterTransaction.

Any suggestion?

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about spring