org.hibernate.MappingException:   invalid   configuration 
说明mapping文件User.hbm.xml有问题.
Caused   by:   org.xml.sax.SAXParseException:   Document   root   element   "hibernate-configuration",   must   match   DOCTYPE   root   "hibernate-mapping". 
说明文件的格式有问题.
文件头有问题
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

解决方案 »

  1.   

    你把hibernate.cfg.xml的文件头用错了,你用的是配置mapping的,是复制的吧,应该用 
    <!DOCTYPE hibernate-configuration
        PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      

  2.   

    谢谢,修改之后还是提示下列错误,还有就是version='1.0'根version="1.0"是不是一样的,谢谢
    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1354)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1288)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1274)
    at ch03.hibernate.Test.main(Test.java:22)
    Caused by: org.dom4j.DocumentException: Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1344)
    ... 3 more
      

  3.   

    这个错误表明你没有把log4j和dom4j等lib文件加入。log4j用于生成log,而dom4j用于解析xml文件。
      

  4.   

    org.dom4j.DocumentException:   Error   on   line   1   of   document     :   Content   is   not   allowed   in   prolog. 
    说明Dom4j读取hibernate.cfg.xml文件有错误,检查一下你的hibernate.cfg.xml文件的格式.
    比如:
    xml文件是UTF-8编码的,如果该文件通过Ultraedit编辑后,会在无BOM头的UTF-8文件中加入BOM,但是DOM4j不认这个BOM(dom4j1.3),解决的办法可以通过升级dom4j到1.6解决www.dom4j.org
    什么是BOM?http://www.unicode.org/faq/utf_bom.html#22
      

  5.   

    我想这不是关键,我也能找到Dom4j和Log4j的包
    Welcome2Hibernate
    src
    JRE_LIB - D:\Sun\AppServer\jdk\jre\lib\rt.jar
    Hibernate3.1
    mysql-connector-java-3.1.14-bin.jar - D:\mysql-connector-java-3.1.14
    Hibernate 3.1 Core Libraries
    antlr-2.7.5H3.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    asm.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    asm-attrs.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    cglib-2.1.3.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    commons-collections-2.1.1.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    commons-logging-1.0.4.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    dom4j-1.6.1.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    ehcache-1.1.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    hibernate3.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    jaas.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    jaxen-1.1-beta-7.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    jdbc2_0-stdext.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    jta.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    log4j-1.2.11.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    xerces-2.6.2.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    xml-apis.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
      

  6.   

    Welcome2Hibernate
    src
    JRE_LIB - D:\Sun\AppServer\jdk\jre\lib\rt.jar
    Hibernate3.1
    mysql-connector-java-3.1.14-bin.jar - D:\mysql-connector-java-3.1.14
    Hibernate 3.1 Core Libraries
    antlr-2.7.5H3.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    asm.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    asm-attrs.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    cglib-2.1.3.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    commons-collections-2.1.1.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    commons-logging-1.0.4.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    dom4j-1.6.1.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    ehcache-1.1.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    hibernate3.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    jaas.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    jaxen-1.1-beta-7.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    jdbc2_0-stdext.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    jta.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    log4j-1.2.11.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.1\lib
    xerces-2.6.2.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
    xml-apis.jar - D:\MyEclipse 5.0GA\eclipse\plugins\com.genuitec.org.hibernate.eclipse_5.0.0\myeclipse-data\3.0\lib
      

  7.   

    我解决了,其实是我的<?xml   version="1.0"   encoding='utf-8'?> 这句之前有空行和空格,呵呵