使用Hibernate连接到MySql服务器时出现NoSuchMethodError

时间:2019-06-05 20:42:43

标签: java mysql glassfish

尝试运行代码并打开glassfish服务器时出现此错误:

CREATE FUNCTION insert_user_test (
    p_username text)
    RETURNS text
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY INSERT INTO users(username) values(p_username));
END $$;

这是我的代码:

java.lang.NoSuchMethodError: org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(Ljava/util/LinkedHashSet;Lorg/hibernate/boot/registry/classloading/spi/ClassLoaderService;)V 

和我的servlet:

public class SessionFact {
static SessionFactory sf;
private static ServiceRegistry serviceRegistry;
public static SessionFactory getSessionFact() {
    Configuration cfg = new Configuration();
    cfg.configure("Resources/hibernate.cfg.xml");
    serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
        cfg.getProperties()).build();
        sf = cfg.buildSessionFactory(serviceRegistry);
        System.out.println("build session factory ---------");
        return sf;
    }   
}

和xml:

public class Testing extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    SessionFactory sf = HelpingClasses.SessionFact.getSessionFact();
    PrintWriter pr = resp.getWriter();
    pr.print("looks like is done");
}
}

0 个答案:

没有答案