Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 休眠缺少提交和回滚?_Java_Hibernate - Fatal编程技术网

Java 休眠缺少提交和回滚?

Java 休眠缺少提交和回滚?,java,hibernate,Java,Hibernate,并在提交和回滚时给我一个错误。tx唯一的方法是getStatus()getTimeout()和setTimeOut(),我不知道如何修复它 import com.atp.servlets.GeneralSetup; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.SessionFactory;

并在提交和回滚时给我一个错误。
tx
唯一的方法是
getStatus()getTimeout()和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;

    }
无法解析方法回滚()

无法解析方法Commit()


您的类路径中似乎没有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>

org.hibernate.javax.persistence
hibernate-jpa-2.1-api
1.0.0.1决赛

类路径中似乎没有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>

org.hibernate.javax.persistence
hibernate-jpa-2.1-api
1.0.0.1决赛

在我看来您使用了错误的依赖项,检查这是否是您的类在我看来您使用了错误的依赖项,检查这是否是您的类pom.xml在哪里?我想我没有。只要下载这个,并添加到类路径,如果你不使用maven@xaa,jpa,这是舞蹈,Hibernate可能是舞蹈演员!pom.xml在哪里?我想我没有。只要下载这个,并添加到类路径,如果你不使用maven@xaa,jpa,这是舞蹈,Hibernate可能是舞蹈演员!