2013-06-25 95 views
2

我想运行一个示例Hibernate程序,它将插入一个值到数据库中,但我得到下面的错误,其中我已经包含slf4j JAR在我的构建路径请帮我解决这个问题。hibernate.cfg.xml配置错误

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

的错误是很明确的,在文件hibernate.cfg.xml在某些时候,你犯了一个错误关闭一个XML标记,可能是>字符缺失(可能在元素hibernate-configuration?)。用一个好的文本编辑器检查文件,它会帮助你找到问题所在。

1

我想你忘了关“>”正确,它只是你可以在hibernate.cfg.xml

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

使用上面没有提到的文档类型编译错误

0

语法,它应该工作。