• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot commit and flush hibernate transaction

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Henry Resheto
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh and baseDao is simply some bean that returns me current session
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should split your test method in more methods marked Transactional without mixing direct and undirect control on transaction (baseDao.getCurrentSession().getTransaction().commit();)
 
reply
    Bookmark Topic Watch Topic
  • New Topic