a different object with the same identifier value was already associated with the session

来源:互联网 发布:数控车椭圆编程实例 编辑:程序博客网 时间:2024/06/13 20:31

解决a different object with the same identifier value was already associated with the session错误

这个错误产生原因在hibernate中同一个session里面有了两个相同标识,但是是不同实体,当这时运行saveOrUpdate(object)操作的时候就会报这个错误。
因为我在实体类的配置中实体之间的关联关系中使用了cascade=”save-update”导致我在新增数据的时候报了以上的错。
我的解决方法是将cascade=”save-update”改为cascade=”none”就可以了。

0 0
原创粉丝点击