java 我可以如何处理 Hibernate 中的“无法解析配置”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7183252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 18:59:09  来源:igfitidea点击:

What can I do with "Could not parse configuration" error from Hibernate?

javahibernateparsingconfiguration

提问by bobetko

I am following Java Hibernate tutorialexample from YouTube. Everything looks great until I try to run code which is supposed to create table Employee on Apache Derby server. I tried to use SQL server (2008) first and I was getting the same error. Could not parse configuration: hibernate.cfg.xmland there is also timeout error. I appreciate any help. Thanks.

我正在关注YouTube 上的Java Hibernate 教程示例。一切看起来都很好,直到我尝试运行应该在 Apache Derby 服务器上创建表 Employee 的代码。我首先尝试使用 SQL Server (2008),但遇到了同样的错误。 无法解析配置:hibernate.cfg.xml并且还有超时错误。我很感激任何帮助。谢谢。

Here is the error I get:

这是我得到的错误:

17:28:51,574  INFO Version:15 - Hibernate Annotations 3.4.0.GA
17:28:51,587  INFO Environment:560 - Hibernate 3.3.2.GA
17:28:51,590  INFO Environment:593 - hibernate.properties not found
17:28:51,594  INFO Environment:771 - Bytecode provider name : javassist
17:28:51,597  INFO Environment:652 - using JDK 1.4 java.sql.Timestamp handling
17:28:51,648  INFO Version:14 - Hibernate Commons Annotations 3.1.0.GA
17:28:51,655  INFO Configuration:1474 - configuring from resource: hibernate.cfg.xml
17:28:51,655  INFO Configuration:1451 - Configuration resource: hibernate.cfg.xml
17:28:51,702 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd]
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
    at com.hibernate.chapter1.TestEmployee.main(TestEmployee.java:14)
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:1532)
    ... 5 more

Here is my hibernate.cfg.xml file:

这是我的 hibernate.cfg.xml 文件:

<?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">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
        <property name="connection.url">jdbc:derby://localhost:1527/HibernateDb;create=true</property>
        <property name="connection.username">user</property>
        <property name="connection.password">password</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">2</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.DerbyDialect</property>

        <!-- Enable Hibernate's current session context -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

    </session-factory>

</hibernate-configuration>

And, here is the code I am running:

而且,这是我正在运行的代码:

package com.hibernate.chapter1;   
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class TestEmployee {
    public static void main(String[] args) {
        AnnotationConfiguration config = new AnnotationConfiguration();
        config.addAnnotatedClass(Employee.class);
        config.configure("hibernate.cfg.xml");

        new SchemaExport(config).create(true, true);
    }    
}

What did I do wrong?

我做错了什么?

回答by Bozho

This means the hibernate.dtd cannot be resolved - its resolution is attempted on the server. The dtd is contained in the jars files - see hereand herefor how to resolve it.

这意味着 hibernate.dtd 无法解析 - 它的解析是在服务器上尝试的。dtd 包含在 jars 文件中 - 请参阅此处此处了解如何解决它。