hibernate.cfg.xml配置错误

时间:2013-06-25 19:42:42

标签: hibernate

我正在尝试运行一个示例Hibernate程序,它会将值插入到数据库中,但是我收到了以下错误,我已经在构建路径中包含了slf4j JAR,请帮我解决这个问题。

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
    at org.test1.HibernateTest.main(HibernateTest.java:18)
Caused by: org.dom4j.DocumentException: Error on line 2 of document  : The document type declaration for root element type "hibernate-configuration" must end with '>'. Nested exception: The document type declaration for root element type "hibernate-configuration" must end with '>'.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
    ... 3 more

3 个答案:

答案 0 :(得分:3)

错误非常明显,在文件hibernate.cfg.xml中的某个位置,您在关闭一个XML标记时出错,可能缺少>个字符(可能在元素hibernate-configuration中?)。使用优秀的文本编辑器检查文件,它将帮助您找到问题所在。

答案 1 :(得分:1)

我想你忘了关闭'>'这恰好是编译错误

答案 2 :(得分:0)

您可能没有在hibernate.cfg.xml

中提到doctype

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

使用上面的语法,它应该工作。