把你的在web.xml文件贴出来看看。

解决方案 »

  1.   

    Configuration().configure()这个方法的参数写你的配置文件的路径....
      

  2.   

    谢谢大家,我没有用到WEB.xml 文档啊 
    hibernate.cfg.xml文档如下:
    <?xml version="1.0" endcoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
    <session-factory>
    <property name="show_sql">
    true
    </property>
    <property name="dialect">
    org.hibernate.dialect.MySQLDialect
    </property>
    <property name="connection.driver_class">
    com.mysql.jdbc.Driver
    </property>
    <property name="connection.url">
    jdbc:mysql://localhost/YF
    </property>
    <property name="connection.user">
    root
    </property>
    <property name="connection.password">
    yaofang
    </property>

    <!-- 以下设置对象与数据库表格映射文件 -->
    <mapping resource="User.hbm.xml"/>
    </session-factory></hibernate-configuration>
      

  3.   

    而且我也按照2楼的朋友那样修改过了,还是不行啊 
    Configuration config = new Configuration().configure("/hibernate.cfg.xml");我得hibernate.cfg.xml文件就是放在工程的目录下的 再 Eclipse中和src目录是一个级别. 再麻烦看看,谢谢!
      

  4.   

    默认是放在根目录下的,比如java code 都是放在src目录下,那么hibernate.cfg.xml也是放在这个目录下,
    或者你试试指定文件的位置,比如放在是src/resource下面,调用new Congiuration().configure("resource/hibernate.cfg.xml");
      

  5.   

    OK  谢谢大家的解答, 现在可以找到文件了 虽然还是有其它异常,我自己再看看.
    我给大家加分. 谢谢了!
    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: resource/hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1354)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1288)
    at caterpillar.hibernate.HibernateDemo.main(HibernateDemo.java:9)
    Caused by: org.dom4j.DocumentException: Error on line 1 of document  : The encoding declaration is required in the text declaration. Nested exception: The encoding declaration is required in the text declaration.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1344)
    ... 2 more
      

  6.   

    一方面是路径不对. 一方面是Eclipse 建立xml文档时  不允许 . 这样的字符存在. 
    不过可以先建立一个 hibernate.xml文档 里面写好了后,在把hibernate.xml 的内容粘贴到hibernate.cfg.xml里么面就可以了.
    不过建立hibernate.cfg.xml文档时 只能 以新建 File的形式 建立文件
      

  7.   

    例如: 
    Configuration config = new Configuration().configure("hibernate/cfg/hibernate.cfg.xml");
    这里面写上你的配置文件路径,就能找到