File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Cannot commit and flush hibernate transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Cannot commit and flush hibernate transaction" Watch "Cannot commit and flush hibernate transaction" New topic
Author

Cannot commit and flush hibernate transaction

Henry Resheto
Greenhorn

Joined: Aug 16, 2013
Posts: 2
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

Joined: Aug 16, 2013
Posts: 2
oh and baseDao is simply some bean that returns me current session
francesco umani
Greenhorn

Joined: Aug 07, 2013
Posts: 27
You should split your test method in more methods marked Transactional without mixing direct and undirect control on transaction (baseDao.getCurrentSession().getTransaction().commit();)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot commit and flush hibernate transaction
 
Similar Threads
Saving objects in database using hibernate
Does this Hibernate generated SQL mean anything to anyone?
Hibernate 3.3.2 not flushing inserts before selects
[Hibernate] Hit the database at a specific moment
Update/Insert optimization in hibernate