[英]Hibernate Exception : Could not parse configuration: hibernate.cfg.xml
i am new to hibernate and tried to execute a simple hibernate jave code but unfortunately i am getting this exception. 我是休眠的新手,试图执行一个简单的休眠jave代码,但不幸的是,我遇到了这个异常。 Somebody has written may be its due to the DOCTYPE , i have used in my configuration file.This is my hibernate.cfg.xml file:
有人写的可能是由于DOCTYPE,我在配置文件中使用过。这是我的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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/userdb</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<mapping resource="employee.hbm.xml" />
</session-factory>
</hibernate-configuration>
and the exception is : 和例外是:
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491) at org.hibernate.cfg.Configuration.configure(Configuration.java:1425) at com.javatpoint.mypackage.StoreData.main(StoreData.java:13) Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481) ... 2 more
线程“主”中的异常org.hibernate.HibernateException:无法解析配置:org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)处的hibernate.cfg.xml org.hibernate.cfg.Configuration.configure( com.javatpoint.mypackage.StoreData.main(StoreData.java:13)处的Configuration.java:1425)原因:org.dom4j.DocumentException:连接被拒绝:connect嵌套异常:连接被拒绝:在org.dom4j.io处连接。 org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)的SAXReader.read(SAXReader.java:484)...还有2个
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
Your DOCTYPE is using the new namespace ( http://www.hibernate.org/dtd/ ) for Hibernate 3.6 , and you might have an older version of the Hibernate libraries in your classpath. 您的DOCTYPE使用的是Hibernate 3.6的新名称空间( http://www.hibernate.org/dtd/ ),并且您的类路径中可能具有较旧版本的Hibernate库。
Replace it with 替换为
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
This one is a temporary solution. 这是一个临时解决方案。 Your Hibernate jars contains dtd for validating your configuration xml.
您的Hibernate jar包含用于验证您的配置xml的dtd。 Extract 'hibernate-configuration-3.0.dtd' and put it in some directory in your project structure (in this case, I have put it in Project root directory).
提取“ hibernate-configuration-3.0.dtd”并将其放在您的项目结构中的某个目录中(在本例中,我将其放置在Project根目录中)。 Add your dtd location to DOCTYPE declaration.
将您的dtd位置添加到DOCTYPE声明中。
<!DOCTYPE hibernate-configuration SYSTEM
"hibernate-configuration-3.0.dtd">
It worked for me. 它为我工作。 It works when system is offline.
当系统离线时,它可以工作。 Fetches DTD from your local system.
从本地系统获取DTD。
Its just that we have to figure a way to fetch dtd from your jar. 只是我们必须找到一种从您的jar中获取dtd的方法。
you may do it this way : 你可以这样:
<!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
but then, it is throwing 但是,它正在抛出
Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.