【解决】MappingException提示Association references unmapped class错误
来源:互联网 发布:网络创业的机会来源 编辑:程序博客网 时间:2024/06/05 05:06
错误代码描述:
Caused by: org.hibernate.MappingException: Association references unmapped class: User
解决问题步骤:
- 查看User有没有写对应的映射文件User.hbm.xml
- 写了映射文件,在hibernate.cfg.xml中有没有注册,注册的路径对不对
<mapping resource="com/fate/oa/domain/User.hbm.xml" />
以上为解决的基本思路,但我遇到的情况以上都没有错误,那就只能是User.hbm.xml写的有问题了。
问题:
一般在映射文件中指定对应的实体类的class有两种方法:
- 在class标签的name属性中指定对应类的全名:
<hibernate-mapping> <class name="com.fate.oa.domain.Role" table="oa_role">
- 在
<hibernate-mapping package="">
的package属性中填写对应的类所在的包名:(推荐使用)
<hibernate-mapping package="com.fate.oa.domain"> <class name="Role" table="oa_role">
发现问题:
到这时候我终于发现我的问题真正的原因是出在我使用了第一种方式。当然,第一种方式是可以的,只是相对麻烦,容易不小心出错。之前映射文件内容简单,没有多对一,一对多等关系映射的时候只需要写本类的class全名,而我也有写,所以没报错。然而当有了复杂的映射关系时,配置时我却忘了给class属性都写上全名,所以出错。由此可见直接写在package上要来得简单,以后都应该用这种方式。
0 0
- 【解决】MappingException提示Association references unmapped class错误
- MappingException提示Association references unmapped class错误的解决方法
- java MappingException提示Association references unmapped class错误的解决方法
- hibernate.MappingException: Association references unmapped class
- Association references unmapped class错误
- 关于Association references unmapped class错误
- Association references unmapped class 错误分析
- : Association references unmapped class
- 解决 Unknown entity class 或 Association references unmapped class
- Hibernate异常:Association references unmapped class
- Hibernate 异常:Association references unmapped class
- Association references unmapped class的解决方法
- HIBERNATE 报 Association references unmapped class
- Hibernate异常Hibernate 异常:Association references unmapped class
- MappingExceptionAssociation references unmapped class错误的解决方法
- hibernate5 报错org.hibernate.boot.MappingException: Association [XX] references an unmapped entity
- org.hibernate.MappingException: An association from the table tuser refers to an unmapped class: Role
- org.hibernate.MappingException: An association from the table STREET refers to an unmapped class: e
- 完美解决 Linux 下 Sublime Text 中文输入
- 计算框架MR
- Poj 1797 Heavy Transportation【Dijkstra变形】
- 25匹马,5条赛道,一匹马一个赛道,比赛只能得到5匹马之间的快慢程度,求1,2,3名
- Leetcode题解 104. Maximum Depth of Binary Tree
- 【解决】MappingException提示Association references unmapped class错误
- 佛五戒
- hadoop作业提交和MapReduce基础分析
- LeetCode-335.Self Crossing
- 调整数组顺序使奇数位于偶数前面
- 移动端App与后台服务的对接方案
- 配置 yum 源--怎么也配置不好,最后选择配置本地yum源
- 对 send 和 recv 的改造
- fastdfs 新添加一个项目的图片目录 实现独立的上传下载功能