I am using Hibernate and Spring:
I have a
unit test like that:
@Test
@Transactional(propagation=Propagation.REQUIRED)
public void testFoo () throws Exception {
Process process = this.bar(); // This calls private method that returns entity object
baseDao.getCurrentSession().getTransaction().commit();
baseDao.getCurrentSession().flush();
this.bar2(process); // This calls another private method
}
Here is the problem: both methods bar() and bar2() get called and execute fine and do what I want them to do, but when I exit method testFoo I gen an exception from a hibernate: "org.springframework.transaction.TransactionSystemException: Could not roll back Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started"
My goal is to save to DB all changes done by method bar() before calling method bar2() what is the proper way to do that?