Hibernate.cfg.xml解析错误

时间:2014-08-21 10:34:11

标签: hibernate hibernate.cfg.xml

<

!DOCTYPE hibernate-configuration PUBLIC  
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  

我的hibernate.cfg.xml文件中有这个。我在eclipse工作区的WEB-INF文件夹中下载了jar(来自http://www.javatpoint.com/src/hb/hibernatejar.zip)。仍然说hibernate.sourceforge.net无法访问。我用www.hibernate.org/dtd替换它,这也是同样的错误。请帮我解决这个问题。

映射文件中也存在同样的问题。

在DOCTYPE中添加类路径后出错:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
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 StoreData.main(StoreData.java:12)
Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
    ... 2 more

2 个答案:

答案 0 :(得分:0)

您的DOCTYPE定义是指DTD上的hibernate.sourceforge.net。现在DTD存在(我可以通过Firefox浏览),但您的应用程序无法访问它。 doctype元素的目的是链接到DTD。

尝试使用以下

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"classpath://org/hibernate/hibernate-mapping-3.0.dtd">

答案 1 :(得分:0)

以下应该是 hibernate.cfg.xml 文件中的完整DTD

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

另外不要忘记在文件的开头跟着

<?xml version='1.0' encoding='utf-8'?>