NonUniqueObjectException问题的解决

来源:互联网 发布:网络催眠音频 编辑:程序博客网 时间:2024/04/30 23:15

     在公司做模块的时候遇到了NonUniqueObjectException 错误,

 

  1. a different object with the same identifier value was already associated with the session: 
  2. [com.......#1462109]; 
  3. nested exception is org.hibernate.NonUniqueObjectException: 
  4. a different object with the same identifier value was already associated with the session: 
  5. [com. .....#1462109]

      看错误的原因是因为针对一个对象加载了引用,由于有多个引用指向一个对象,在你去update的时候,出现了对象不同步问题,hibernate不知道要保存哪个对象,查了下原因,原来是我所做的hibernate映射在主表中对子表做映射的时候设置了lazy="false",这样主表在查取数据的时候就会相应的也把子表的数据取出来,然后在子表的编辑页面做update操作的时候就又加载了一个引用,现在去更新它的时候,hibernate就不知道更新哪个了。

     解决办法,将lazy="true" 或者默认不设置即可。

原创粉丝点击