尝试保存在MySQL数据库中时发生异常

穆罕默德·阿里·索莱曼尼(Mohammad Ali Soleymani)

我想创建一个Web服务以在MySQL中保存帐户:

package didList;

import javax.jws.WebService;

@WebService
public class Accounts {

public Integer addAccount(String fullName, String username, String password, Boolean isAdmin , Boolean isShowInList){
    Taccount person = new Taccount (fullName,username,password,isAdmin , isShowInList);
    System.out.println("test1");
    AccountManager SVTDB = new AccountManager();
    System.out.println("test2");
    return SVTDB.addAccount(person);
  }
}

它在此行之前打印“ test1”:

AccountManager SVTDB = new AccountManager();

但它不打印“ test2”,所以该行有问题,

package didList;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class AccountManager {
    private static SessionFactory factory;

    public AccountManager() {
        try {
            NewHibernateUtil.initConnection();
            factory = NewHibernateUtil.getSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);

        }
}

public Integer addAccount(Taccount acc) {
    Session session = factory.openSession();
    Transaction tx = null;
    Integer accID = null;
    try {
        tx = session.beginTransaction();
        accID = (Integer) session.save(acc);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return accID;
 }
}

这是NewHibernateUtil类:

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class NewHibernateUtil {

private static SessionFactory sessionFactory;

public static void initConnection() {
    try {
        sessionFactory = createSessionFactory();
    } catch (Throwable ex) {
        // Log the exception. 
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }

}

private static SessionFactory createSessionFactory() {
    Configuration config = new Configuration();
    config.configure("hibernate.cfg.xml");
    return config.buildSessionFactory();
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}
}

这是我看到的异常:

java.lang.NoClassDefFoundError: org/hibernate/HibernateException
    at didList.Accounts.addAccount(Accounts.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.glassfish.webservices.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:144)
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:136)
    at org.glassfish.webservices.MonitoringPipe.process(MonitoringPipe.java:142)
    at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:136)
    at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:209)
    at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:141)
    at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:419)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:868)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169)
    at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:169)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1783)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1633)
    ... 62 more
尼克什乔希

将hibernate jar文件添加到项目的类路径中。

If you are using eclipse or netbeans simply add the jar file from 
hibernate/lib/required folder into build path of the IDE.
If you are not using any IDE any go to advance system setting and set 
classpath of all jar files.

不要忘记将休眠库也放在lib文件夹中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试保存在MySQL数据库中时发生异常

来自分类Dev

在MySQL数据库中输入日期时发生异常

来自分类Dev

数据未保存在Mysql数据库中

来自分类Dev

尝试使用H2数据库更新JDBC ResultSet时发生异常

来自分类Dev

尝试使用H2数据库更新JDBC ResultSet时发生异常

来自分类Dev

显示保存在mysql数据库中的发布时,css框中出现的文本

来自分类Dev

尝试保存新数据时发生未处理的异常

来自分类Dev

尝试更新Access数据库时发生OleDbException

来自分类Dev

尝试在cakephp中上传图片并将路径保存在数据库中

来自分类Dev

插入数据mysql数据库时发生错误

来自分类Dev

尝试将未处理的异常插入SQL Server数据库时,对象类型不存在任何映射

来自分类Dev

Cakephp使用create循环将数组数据保存在MySql数据库中

来自分类Dev

尝试在mysql数据库中加载数据时出错

来自分类Dev

在生产环境中设置mysql数据库时发生错误

来自分类Dev

为什么在MySQL数据库中创建表时总是发生此错误?

来自分类Dev

尝试绑定XAML数据时发生异常

来自分类Dev

使用Android Camera Preview拍照并保存在SQL数据库中时崩溃了

来自分类Dev

建立CMS时可以将大量的html内容保存在数据库中吗

来自分类Dev

无法编辑保存在数据库中的数据

来自分类Dev

数据未保存在数据库中

来自分类Dev

将数据保存在 sqlite 或 firebase 数据库中?

来自分类Dev

HTML canvas保存在mysql数据库上

来自分类Dev

需要知道保存在MySQL数据库中的字节数组的类

来自分类Dev

上传多个图像并将名称保存在数据库PHP MySQL中

来自分类Dev

Rails 4将错误的UTC保存在MySQL数据库中

来自分类Dev

如何使用Python将图像保存在mysql数据库中?

来自分类Dev

将格式化的文本保存在mysql数据库中

来自分类Dev

将图像保存在mysql数据库中的有效方法

来自分类Dev

Android应用程序未保存在mysql数据库中

Related 相关文章

  1. 1

    尝试保存在MySQL数据库中时发生异常

  2. 2

    在MySQL数据库中输入日期时发生异常

  3. 3

    数据未保存在Mysql数据库中

  4. 4

    尝试使用H2数据库更新JDBC ResultSet时发生异常

  5. 5

    尝试使用H2数据库更新JDBC ResultSet时发生异常

  6. 6

    显示保存在mysql数据库中的发布时,css框中出现的文本

  7. 7

    尝试保存新数据时发生未处理的异常

  8. 8

    尝试更新Access数据库时发生OleDbException

  9. 9

    尝试在cakephp中上传图片并将路径保存在数据库中

  10. 10

    插入数据mysql数据库时发生错误

  11. 11

    尝试将未处理的异常插入SQL Server数据库时,对象类型不存在任何映射

  12. 12

    Cakephp使用create循环将数组数据保存在MySql数据库中

  13. 13

    尝试在mysql数据库中加载数据时出错

  14. 14

    在生产环境中设置mysql数据库时发生错误

  15. 15

    为什么在MySQL数据库中创建表时总是发生此错误?

  16. 16

    尝试绑定XAML数据时发生异常

  17. 17

    使用Android Camera Preview拍照并保存在SQL数据库中时崩溃了

  18. 18

    建立CMS时可以将大量的html内容保存在数据库中吗

  19. 19

    无法编辑保存在数据库中的数据

  20. 20

    数据未保存在数据库中

  21. 21

    将数据保存在 sqlite 或 firebase 数据库中?

  22. 22

    HTML canvas保存在mysql数据库上

  23. 23

    需要知道保存在MySQL数据库中的字节数组的类

  24. 24

    上传多个图像并将名称保存在数据库PHP MySQL中

  25. 25

    Rails 4将错误的UTC保存在MySQL数据库中

  26. 26

    如何使用Python将图像保存在mysql数据库中?

  27. 27

    将格式化的文本保存在mysql数据库中

  28. 28

    将图像保存在mysql数据库中的有效方法

  29. 29

    Android应用程序未保存在mysql数据库中

热门标签

归档