本人看北京尚学堂的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配置有问题.但是我又不知道到底是什么问题.)
谢谢大家了
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配置有问题.但是我又不知道到底是什么问题.)
谢谢大家了
另外我觉得2楼已经说的很明白了可能是文件没拷贝到web-inf/classes目录下吧,编辑一下User.hbm.xml或者手动拷贝如果还不行,就把你hibernate.cfg.xml的resource那段贴出来
查查看吧,可能是这个原因
我是用插件启动TOMCAT报的错(TOMCAT里面的workspace路径已经配过了),如果在eclipse里的server里new一个新的,再在把项目放进去启动的话就不再有错了,虽然不知道为什么,但问题解决了,希望有对你有帮助
src
src/hibernate
src/common
src/xfImportInfo
.
.
.
.
我用上了Spring hibernate 和freemaker
<mapping resource="org.abc.hibernate.model/Student.hbm.xml" />错误
No grammar constraints (DTD or XML schema) detected for the document.
盼高手支招!
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”,保存后重新运行,运行成功。
以上是我遇到的问题,希望和大家的困惑一样。找错误真的很浪费时间!