我遇到的两个hibernate异常

一、
问题:[b]Source not found for AttachmentManager$$FastClassByCGLIB$$5f0a3cd1.invoke(int, Object, Object[]) line: not available

ReflectiveMethodInvocation: public void com.openjeecms.manager.AttachmentManager.save(com.openjeecms.beans.Attachment); target is of class [com.openjeecms.manager.AttachmentManager]

java.lang.NoSuchMethodError: org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/event/EventSource;

java.lang.reflect.InvocationTargetException[/b]
回答:将validator升级到hibernate-validator-4.0.0.Beta1.jar就可以了。
二、
问题:
假定,Parent类有一个Set属性,里面放的是Son。如果查询"from Parent",某个Parent哪怕一个Son都没有,那个Set属性不会为null,而是一个空集合。
这时候如果你Parent newP=new Parent();然后BeanUtils.copyPropertis(newP,origP);最后就会报hibernate异常"Found shared references to a collection"。
注:hibernate在什么时机发现"两个对象共享一个集合"的情况的?我这边的例子是在下一次查询时发现的。

原因:
BeanUtils.copyPropertis是浅拷贝,导致这两个对象引用的Set是同一个Set,这在hibernate中是不允许的,参见Hibernate reference第6章的"Two entities may not share a reference to the same collection instance"。
这种问题常见于复制对象时。
如何解决:newP.setSonSet(null);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值