org.hibernate.MappingException: Unknown entity:
来源:互联网 发布:湖南有色行情分析软件 编辑:程序博客网 时间:2024/05/21 10:09
许多初学者在学习Hibernate的时候,总会遇到这样的问题。org.hibernate.MappingException: Unknown entity: ******
今天我在调试程序的时候也遇到了此问题,最终终于解决,下面我的一些总结下。
一句话:“因为你的映射文件(*.hbm.xml) 没有被映射”
问题出现的原因,有几下几点:
1,检查你的映射文件的名字是否和你的pojo(*.java)的名字是否相同。
2.映射文件的名字是*.hbm.xml而不是*.xml
3.你是否加载了你的映射文件。
加载的方法有两种
(1)在你的Hibernate.cfg.xml配置文件中加载映射文件
<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
…………
…………
<!-- 用于记载映射文件Student.hbm.xml-->
<mapping resource="com/Students.hbm.xml"/>
</session-factory>
</hibernate-configuration>
(2)在你的测试代码的加载映射文件
Configuration cfg = new Configuration();
cfg.configure();
cfg.addClass(*.class); 这里的*.class是你的映射文件的名字*.hbm.class中的*。。。
但是你要注意,用第二种方法加载的时候,你的*.hbm.class文件必须位于classpath下面。
原文出处;http://jiang5769156.iteye.com/blog/736919
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity:
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity:
- org.hibernate.MappingException: Unknown entity:
- org.hibernate.MappingException: Unknown entity:
- org.hibernate.MappingException: Unknown entity:
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity
- org.hibernate.MappingException: Unknown entity:
- org.hibernate.MappingException: Unknown entity:
- org.hibernate.MappingException: Unknown entity
- Hibernate 5 :- org.hibernate.MappingException: Unknown entity
- H5 Clock
- 413. Arithmetic Slices**
- 有n个人围成一圈,顺序排号,从第一个开始报数(从1到m报数),凡报到m的人退出圈子,问最后最后留下的是原来第几号的那位
- JVM内存区域--堆栈方法区等概念理解
- recovery字库相关,如何修改字库文件
- org.hibernate.MappingException: Unknown entity:
- SDL_ShowCursor函数
- JSP---网上商城购物车
- Web作业
- CSS 图片不停旋转
- 严重:Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/E:/Tomc
- 用python批量抓取上市公司财务数据
- CSS中定位实例
- [网易博客]软技能读后感