我能做些什么"无法解析配置"来自Hibernate的错误? [英] What can I do with "Could not parse configuration" error from Hibernate?
问题描述
我遵循YouTube的 Java Hibernate教程。在我尝试运行应该在Apache Derby服务器上创建表Employee的代码之前,一切看起来都很棒。我试图先使用SQL服务器(2008),并得到相同的错误。
无法解析配置:hibernate.cfg.xml ,并且还存在超时错误。我感谢任何帮助。感谢。
以下是我得到的错误:
17:28:51,574信息版本:15 - Hibernate Annotations 3.4.0.GA
17:28:51,587信息环境:560 - Hibernate 3.3.2.GA
17:28: 51,590信息环境:593 - 找不到hibernate.properties
17:28:51,594信息环境:771 - 字节码提供程序名称:javassist
17:28:51,597信息环境:652 - 使用JDK 1.4 java.sql 。时间戳处理
17:28:51,648信息版本:14 - Hibernate Commons Annotations 3.1.0.GA
17:28:51,655信息配置:1474 - 从资源配置:hibernate.cfg.xml
17:28:51,655信息配置:1451 - 配置资源:hibernate.cfg.xml
17:28:51,702 DEBUG DTDEntityResolver:64 - 试图解析系统ID [http://www.hibernate.org /dtd/hibernate-configuration-3.0.dtd]
线程main中的异常org.hibernate.HibernateException:无法解析配置:hibernate.cfg.xml
at org.hibernate.cfg.Configurati on.doConfigure(Configuration.java:1542)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:
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)
导致:org.dom4j.DocumentException:连接超时:connect嵌套异常:连接超时:在org.dom4j连接
。 io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
... 5 more
$ b这是我的hibernate.cfg.xml文件:
<?xml version ='1.0'encoding ='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://www.hibernate.org/dtd/hibernate-configuration -3.0.dtd>
< hibernate-configuration>
< session-factory>
<! - 数据库连接设置 - >
< 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>密码< / property>
<! - JDBC连接池(使用内置) - >
< property name =connection.pool_size> 2< / property>
<! - - SQL方言 - >
< property name =dialect> org.hibernate.dialect.DerbyDialect< / property>
<! - 启用Hibernate的当前会话上下文 - >
< property name =current_session_context_class>线程< / property>
<! - 禁用二级缓存 - >
< property name =cache.provider_class> org.hibernate.cache.NoCacheProvider< / property>
<! - 将所有执行的SQL回复到stdout - >
< property name =show_sql> true< / property>
<! - 在启动时删除并重新创建数据库模式 - >
< property name =hbm2ddl.auto>建立< / 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);
新建SchemaExport(config).create(true,true);
$ / code>我做错了什么?
解决方案这意味着hibernate.dtd无法解析 - 它的解析是在服务器上尝试的。 dtd包含在jar文件中 - 请参阅此处和< a href =http://forum.springsource.org/showthread.php?80886-How-to-configure-hibernate.cfg.xml-to-work-offline =noreferrer> here for如何解决它。
I am following Java Hibernate tutorial example 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.xml and there is also timeout error. I appreciate any help. Thanks.
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:
<?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?
解决方案This means the hibernate.dtd cannot be resolved - its resolution is attempted on the server. The dtd is contained in the jars files - see here and here for how to resolve it.
这篇关于我能做些什么"无法解析配置"来自Hibernate的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!