Java “我能用它做什么?”;无法分析配置";来自Hibernate的错误?

Java “我能用它做什么?”;无法分析配置";来自Hibernate的错误?,java,hibernate,parsing,configuration,Java,Hibernate,Parsing,Configuration,我正在遵循YouTube上的例子。在我尝试运行应该在ApacheDerby服务器上创建表Employee的代码之前,一切看起来都很好。我首先尝试使用SQL server(2008),但我得到了相同的错误。 无法分析配置:hibernate.cfg.xml,还有超时错误。谢谢你的帮助。谢谢 以下是我得到的错误: 17:28:51,574 INFO Version:15 - Hibernate Annotations 3.4.0.GA 17:28:51,587 INFO Environment:

我正在遵循YouTube上的例子。在我尝试运行应该在ApacheDerby服务器上创建表Employee的代码之前,一切看起来都很好。我首先尝试使用SQL server(2008),但我得到了相同的错误。 无法分析配置:hibernate.cfg.xml,还有超时错误。谢谢你的帮助。谢谢

以下是我得到的错误:

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
<?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>
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);
    }    
}
这是我的hibernate.cfg.xml文件:

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
<?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>
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);
    }    
}

我做错了什么?

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

感谢您抽出时间回复。我已经查看了我的hibernater3.jar,其中有一个名为“hibernate-configuration-3.0.dtd”的文件,这正是hibernate.cfg.xml声明中提到的。看看其他帖子,我注意到我使用的路径是不同的。我的路径是:而其他人使用:。我改变了道路,现在一切都正常了。问题是,我认为它仍然是从互联网上提取的,而不是从我的hibernate3.jar中提取的。有没有办法强制从本地资源加载它。谢谢。您的dtd没有从internet上删除。。您指定的dtd的uri应该与jar中dtd中提到的uri匹配。它看起来像是打开了一个网站,但不是从那里拉出来的。。