hibernate在hibernate.cfg.xml中只配置一个User.hbm.xml映射文件时没问题,但配置多个就报错

qq761130493 2018-10-31 10:13:45
<mapping resource="com/qst/giftems/user/pojos/User.hbm.xml" />
<mapping resource="com/qst/giftems/gift/pojos/Gift.hbm.xml"/>
<mapping resource="com/qst/giftems/gift/pojos/GiftStyle.hbm.xml"/>
<mapping resource="com/qst/giftems/gift/pojos/GiftType.hbm.xml"/>
<mapping resource="com/qst/giftems/order/pojos/Order.hbm.xml"/>
<mapping resource="com/qst/giftems/order/pojos/OrderItem.hbm.xml"/>
主要报错如下:
org.hibernate.MappingException: Association references unmapped class: com/qst/giftems/gift/pojos/GiftStyle
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/qst/giftems/user/pojos/User.hbm.xmll
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.qst.giftems.user.pojos.User
...全文
96 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveunittesting 2018-11-02
  • 打赏
  • 举报
回复
写错了,从你日志最下面的原因找,Duplicate class/entity mapping com.qst.giftems.user.pojos.User,User类映射了2次,肯定是。xml李,你从User.htm.xml copy 到GiftStyle.hbm.xml,而没有修改类名
loveunittesting 2018-11-02
  • 打赏
  • 举报
回复
报错是:unmapped class: com/qst/giftems/gift/pojos/GiftStyle 我看映射是<mapping resource="com/qst/giftems/gift/pojos/GiftStyle.hbm.xml"/> 不知道是不是包名写错了导致的。 目前你类里面用的应该是com/qst/giftems/gift/pojos/GiftStyle,而你做映射的是com/qst/giftems/gift/pojos/GiftStyle。 起码从你配置看是这样。
qq761130493 2018-11-02
  • 打赏
  • 举报
回复
引用 3 楼 yys79 的回复:
写错了,从你日志最下面的原因找,Duplicate class/entity mapping com.qst.giftems.user.pojos.User,User类映射了2次,肯定是。xml李,你从User.htm.xml copy 到GiftStyle.hbm.xml,而没有修改类名

照你说的检查过了,没发现有你所说的问题
jofoever 2018-10-31
  • 打赏
  • 举报
回复
这样写是没有什么问题的,我曾经也写过,应该是你的路径有错误,查看以下文件名,路径有没有写错,字母大小写之类的

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧