本人看北京尚学堂的hibernate视频,看第一个例子就遇到一个摸不着头脑的问题,源码如下:package com.bjsxt.hibernate;import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;public class ExportDB { public static void main(String[] args) {

//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();

SchemaExport export = new SchemaExport(cfg);

export.create(true,true);
}
}
会报这个错误:
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com/bjsxt/hibernate/User.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:517)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1511)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at com.bjsxt.hibernate.ExportDB.main(ExportDB.java:11)
Usr.hbm.xml是绝对路径正确且配置也正确的.我检查了几次了.但是还是出现这种错误.我网上搜索了一些资料,说我这种情况很有可能是不能解析Configuration所造成的.可是我已经正确导入了Configuration所在的包了.我现在该怎么办才能调出这个错误.
(源码肯定是正确的,因为我看视频里尚学堂的老师可以运行这个程序.我怀疑是不是我的MyEclipse配置有问题.但是我又不知道到底是什么问题.)
谢谢大家了

解决方案 »

  1.   

    还有,但点击hibernate.cfg.xml文件时.MyEclispe会报:This project is not a MyEclipse Hibernate Project. Assuming Hibernate 3 capablites for the configuration editor.这样的警告信息.我不知道该怎么办.
      

  2.   

    User.hbm.xml 要放到com/bjsxt/hibernate包下。
      

  3.   

    这个编辑器问题,不用在乎,用xml打开就可以了
    另外我觉得2楼已经说的很明白了可能是文件没拷贝到web-inf/classes目录下吧,编辑一下User.hbm.xml或者手动拷贝如果还不行,就把你hibernate.cfg.xml的resource那段贴出来
      

  4.   

    你看看那些xml文件在classes下有没有
      

  5.   

    有可能是这样的,比如你这个工程的package是XXXX.YYYY,部署的时候,有可能在classes下是XXXX的下级目录中有一个YYYY,然后里面是你的Usr.hbm.xml文件。而你的hibernate.cfg.xml里的mapping段是XXXX.YYYY/Usr.hbm.xml
    查查看吧,可能是这个原因
      

  6.   

    我也遇到了你说的情况,在检查过绝对不是路径问题后,很无奈。
    我是用插件启动TOMCAT报的错(TOMCAT里面的workspace路径已经配过了),如果在eclipse里的server里new一个新的,再在把项目放进去启动的话就不再有错了,虽然不知道为什么,但问题解决了,希望有对你有帮助
      

  7.   

    嗨  小女子刚刚接触Hibernate 今天遇到了同样的问题 不知楼主当时是怎么解决的  可否指点一二
      

  8.   

    有没有碰到过这样的情况hibernate/cn.detech.gxtelecom.hibernate/XfCity.hbm.xml 这个路径对不对,我和楼主一样报错了这样的错。我是Source Folder 新建的一个src/hibernate下面的包名是这个cn.detech.gxtelecom.hibernate
      

  9.   

    我是项目是这样排版的
    src
    src/hibernate
    src/common
    src/xfImportInfo
    .
    .
    .
    .
    我用上了Spring hibernate 和freemaker
      

  10.   

    <mapping resource="org/abc/hibernate/model/Student.hbm.xml" />正确
    <mapping resource="org.abc.hibernate.model/Student.hbm.xml" />错误
      

  11.   

    你这样的问题我也遇到过,而且问题是一模一样的;错误也是一样的。原因是在Jar包中出现了一些重复的jar包,所以导致程序的运行错误,你可以从Java的jar包出发,我说的是Hibernate jar包中可能出现很多重复的,从这入手,希望你能成功解决这个难题!
      

  12.   

    我也是在学习尚学堂教程时候遇到的问题,和楼主一样。再次强调路径觉得没问题。只有映射文件上一个警告(.hbm.xml)
    No grammar constraints (DTD or XML schema) detected for the document.
    盼高手支招!
      

  13.   

    我用的eclipse helio 是要用jbpm开发公文处理系统工程分布图如下 
       jbpm
          src/main/java
               com/bjsxt.jbpm
                      Document.java
                      JBPM_CreatDocument.java
                       Document.hbm.xml
    当我运行JBPM_CreatDocument.java,报出如下错误:
           resource: com/bjsxt/jbpm/Document.hbm.xml not found
    我大事很郁闷,因为配置都对,就是运行出错。于是放弃手写代码的方法,想用hibernate自动生成,就从网上下载hibernate插件,安装都单击 Hibernate.hbm.xml,在session factory重新配置mapping为
    resource=“com/bjsxt/jbpm/ Document.hbm.xml”,保存后重新运行,运行成功。
    以上是我遇到的问题,希望和大家的困惑一样。找错误真的很浪费时间!
      

  14.   

    我是按18楼的做,成功了是jar包弄错了
      

  15.   

    除了拼命检查 hbm.xml以为,还有可能是jar的问题,我在myeclipse新建web工程的时候选择了java ee 6.0,但是我在导入hibernate包时候选择的是java ee 5.0.所以出现了:org.hibernate.MappingNotFoundException: resource: ***hbm.xml not found问题,希望有帮助!