小弟我最近在学习hibernate,但是自己写hibernate应用时却出现了很多问题,都没有真正运行过一个hibernate应用;
1. 我导入包时导入的都是从hibernate.org下载的hibernate3解压后的hibernate3.jar以及lib文件夹下面的jar包,但是运行的时候好像还提示我缺少了jar包,好像是slf4j的相关的包,根据他的错误提示后才解决这个问题;但是我就想知道难道使用hibernate3.jar及同文件下达lib文件里的jar包还不够吗(当然还加了数据库的驱动jar包)?2.现在好像是没有提示缺少jar包了,但是还是报错,望大家帮忙解释并解决一下,错误信息为:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.MyTest.main(MyTest.java:16)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1528)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1448)
at com.HibernateUtil.<clinit>(HibernateUtil.java:11)
... 1 more
Caused by: org.dom4j.DocumentException: Error on line 1 of document  : The processing instruction must begin with the name of the target. Nested exception: The processing instruction must begin with the name of the target.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
... 4 more另:我的应用很简单,hibernate.cfg.xml的配置和位置应该都没有问题

解决方案 »

  1.   

    从报错的原因看是它说无法解析你的hibernate.cfg.xml 文件
    你用的MyEclipse吗?你有把Spring整合进去吗?我的hibernate问题就是在Mye下的\WEB-INF\lib里有个asm-2.2.3.jar
    的文件冲突把asm-2.2.3.jar文件删啦就可以了,但是我还没遇到过你这种问题还是版本的问题,你用Mye导入hibernate就没事啦,不知道能帮上你的忙不
      

  2.   

    The processing instruction must begin with the name of the target.
    还是再检查检查你的配置xml。
      

  3.   

    <? xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    <session-factory>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mysql</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">root</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <mapping resource="./Admin.hbm.xml"/>
    </session-factory>
    </hibernate-configuration>
    这有什么问题吗
      

  4.   

    1.有些情况下,也需要第三方的包。不过使用myeclipse时,有时会提示缺少log4j,但是不用也没有问题的
    2.配置文件没有问题,是你导入的包有问题。
    你重新找个完整的hibernate包导入吧。最好使用myeclipse插件
      

  5.   

    最好是使用MyEclipse自动导入吧,否则jar包版本冲突很常见的。