Hibernate工具 - 无法添加配置 - dom4j连接Timedout -

时间:2015-06-23 11:56:22

标签: java hibernate xml-dtd hibernate.cfg.xml dtd-parsing

我今天在公司创建了一个小项目。在Hibernate Perspective中,我尝试添加新配置,以便我可以从具有多个列的db表中轻松创建实体。但是当我选择我的项目时,它会给我org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

完成堆栈跟踪 -

org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
    at org.jboss.tools.hibernate.proxy.ConfigurationProxy.configure(ConfigurationProxy.java:100)
    at org.hibernate.console.ConfigurationFactory.loadConfigurationXML(ConfigurationFactory.java:355)
    at org.hibernate.console.ConfigurationFactory.configureStandardConfiguration(ConfigurationFactory.java:279)
    at org.hibernate.console.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:174)
    at org.hibernate.console.ConfigurationFactory.createConfiguration(ConfigurationFactory.java:96)
    at org.hibernate.eclipse.console.common.HibernateExtension$5.execute(HibernateExtension.java:166)
    at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
    at org.hibernate.eclipse.console.common.HibernateExtension.execute(HibernateExtension.java:189)
    at org.hibernate.eclipse.console.common.HibernateExtension.buildWith(HibernateExtension.java:163)
    at org.hibernate.eclipse.console.common.HibernateExtension.build(HibernateExtension.java:134)
    at org.hibernate.console.ConsoleConfiguration.build(ConsoleConfiguration.java:189)
    at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:43)
    at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:98)
    at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:104)
    at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:238)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
    ... 18 more

即使使用了许多hibernate版本并多次更改DTD,我也无法弄清楚问题。有人可以帮我这个。它是一个简单的maven项目,而.cfg.xml文件放在src / main / java

我甚至从这个网址http://www.mkyong.com/hibernate/maven-3-hibernate-3-6-oracle-11g-example-xml-mapping/下载了一个简单的项目,然后尝试添加新配置但又遇到了同样的问题。我只是更改了我拥有的相应数据库凭据。它们是正确的,因为使用相同的jdbc url我已成功在Data Source Explorer中创建了新的数据库连接。 请帮助。

互联网在我公司工作正常。

2 个答案:

答案 0 :(得分:1)

尝试更改hibernate.cfg.xml中的DTD定义:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

为:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

这样,XML解析器不会尝试从Internet加载DTD文件,但会尝试从Hibernate jar加载它。

答案 1 :(得分:1)

您可以打开配置文件抛出Web浏览器(firefox),检查您的配置文件是否正常。如果有什么问题,浏览器会向您显示。 我指的是(http://blog.csdn.net/caixiexin/article/details/7024623)。