xaa xaa - 3 years ago 216
Java Question

Hibernate missing Commit and Rollback?

I'm following this guide and gives me an error on

Commit and Rollback
. The only methods
has is
getStatus() getTimeout() and setTimeOut()
and I have no idea how to fix it.

import com.atp.servlets.GeneralSetup;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public Integer addGeneralSetup(String name) {
Session session = factory.openSession();
Transaction tx = null;
Integer employeeID = null;
tx = session.beginTransaction();
GeneralSetup employee = new GeneralSetup();
employeeID = (Integer) session.save(employee);
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
}finally {
return employeeID;


Cannot resolve method Rollback()

Cannot resolve method Commit()

Answer Source

It seems that you do not have javax.persistence API library in your classpath.

org.hibernate.Transaction extends from javax.persistence.EntityTransaction interface and the rollback and commit methods are from there.

Try adding this dependency to your pom.xml

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download