我怎么能用Hibernate的“无法解析配置”错误?

我正在关注YouTube上的Java Hibernate教程示例。 在我尝试运行应该在Apache Derby服务器上创建表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 

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

      org.apache.derby.jdbc.ClientDriver jdbc:derby://localhost:1527/HibernateDb;create=true user password  2  org.hibernate.dialect.DerbyDialect  thread  org.hibernate.cache.NoCacheProvider  true  create   

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

 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包含在jar文件中 – 请参阅此处和此处了解如何解决它。