java - Hibernate 工具 - 无法添加配置 - dom4j 连接超时 -

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

我今天在公司创建了一个小项目。在 Hibernate Perspective 中,我尝试添加新配置,以便我可以从具有多个列的数据库表轻松创建实体。但是当我选择我的项目时,它给我 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 在数据源资源管理器中成功创建了一个新的数据库连接。 请帮忙。

Internet 在我公司工作正常。

最佳答案

尝试更改 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 加载它。

关于java - Hibernate 工具 - 无法添加配置 - dom4j 连接超时 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31002130/

相关文章:

java - Spring Data CrudRepository 应用自动级联类型

java - 4.0 XSD 上的 Hibernate 异常

java - Spring boot @ExceptionHandler 未捕获子类异常

java - 线程中的异常 "main"java.lang.StringIndexOutOfBoundsException : String index out of range: -1

java - “多对一”属性类型不应为 'Persistence Entity'

java - 如何更改对象在 spring-data/hibernate/rest 中返回的方式

java:如何获取时区缩写(从偏移量)?

java - 使用 org.apache.commons.ObjectUtil 类对自定义对象进行空安全检查

xml - 在 XML 架构中使用实体 'constants'

xml - DTD 究竟是什么?