日期:2014-05-20  浏览次数:20804 次

org.hibernate.MappingNotFoundException
本人看北京尚学堂的hibernate视频,看第一个例子就遇到一个摸不着头脑的问题,源码如下:
Java code

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配置有问题.但是我又不知道到底是什么问题.)
谢谢大家了

------解决方案--------------------
User.hbm.xml 要放到com/bjsxt/hibernate包下。
------解决方案--------------------
探讨
还有,但点击hibernate.cfg.xml文件时.MyEclispe会报:This project is not a MyEclipse Hibernate Project. Assuming Hibernate 3 capablites for the configuration editor.这样的警告信息.我不知道该怎么办.