I'm following this guide并在Commit and Rollback
上给我一个错误。 tx
唯一的方法是getStatus() getTimeout() and setTimeOut()
,我不知道如何修复它。
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;
try{
tx = session.beginTransaction();
GeneralSetup employee = new GeneralSetup();
employeeID = (Integer) session.save(employee);
tx.commit();
}catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}finally {
session.close();
}
return employeeID;
}
无法解析方法Rollback()
无法解析方法Commit()
答案 0 :(得分:0)
您的类路径中似乎没有javax.persistence API库。
org.hibernate.Transaction
从javax.persistence.EntityTransaction
界面延伸,rollback
和commit
方法来自那里。
尝试将此依赖项添加到您的pom.xml
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>