I run my DAO tests within JUnit test class that has proper @ContextConfiguration and @RunWith annotations attached. Individual tests put some data to database and check sanity. They are expected to clean up database state after that. There is an easy way - mark methods/class as @Transactional, then methods are executed within a transaction and rollback happens as it should.
The problem is that this approach to DAO testing does not fully simulate the environment. Say, I have some lazy-loaded collection field in my JPA entity. In my controller code I get this entity with myDao.getMyEntity(id) call and iterate over lazy collection. What I get in application runtime is a LazyInitializationException, but this won't happen in my test as it is actually transactional. How do I run my tests with tests not being @Transactional, but data still being cleared up on test end?
I use in-memory HSQLDB for tests if it makes any difference.