java - org.dom4j.DocumentException : Connection timed out: connect and Nested exception: Connection Nested exception

标签 java hibernate

我更换了电脑,并重新安装了所有版本:tomcat 8 和 6、netbeans 8、jdk 1.7、hibernate 4.3.4,但是当我运行 Web 应用程序时,出现此错误。 过去使用我的旧电脑时,我没有出现此错误,但代码和库是相同的,当我尝试从数据库获取数据时会发生此错误

SEVERE: Servlet.service() for servlet Controller threw exception
org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
..cut..
Nested exception: 
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
..cut..
SEVERE: Servlet.service() for servlet Controller threw exception
java.lang.NoClassDefFoundError: Could not initialize class ..cut..HibernateUtil
at my.package.data.DataAccess.getUser(DataAccess.java:38)

这是 HibernateUtil.java:

package my.package;

import org.hibernate.SessionFactory;
import org.hibernate.service.*;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory1();

    private static SessionFactory buildSessionFactory1() 
    {
        Configuration configuration = new Configuration().configure(); 
        StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
        serviceRegistryBuilder.applySettings(configuration.getProperties());
        ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
        return configuration.buildSessionFactory(serviceRegistry);
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void shutdown() {
        getSessionFactory().close();
    }
}

最佳答案

我发现问题:我已经将 hibernate 3 和 hibernate 4 添加到项目中,可能存在一些冲突。现在我只有 hibernate 4 并且没有问题

关于java - org.dom4j.DocumentException : Connection timed out: connect and Nested exception: Connection Nested exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24528263/

相关文章:

java - 当应用程序从后台进入前台时,如何显示特定 Activity ?

java - 波兰语中数字组分隔符的 ISO 字符是什么?

java - 如何预先加载实体列表?

java - 应用程序级锁定和 hibernate 乐观锁定

java - Junit测试导致Mysql元数据锁

java - Spring Boot 配置文件不选择属性文件

java - 无法创建实例 - 构造函数具有私有(private)访问权限

java - 反射-EasyMock-ClassCastException

java - Hibernate:投影 JPQL 查询到 DTO 问题

java - 日期被添加到数据库中,但月份增加了一个。这是为什么?