org.hibernate.NonUniqueObjectException的异常,很蛋疼

org.hibernate.NonUniqueObjectException的错误,很蛋疼org.hibernate.NonUniqueObjectException: a differ

org.hibernate.NonUniqueObjectException的错误,很蛋疼

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 


我要级联删除一个对象,这个错误纠结的很久,往上说的都是session.clean()或者session.refresh(object)方法就可以解决了,不过在我的程序里面没有解决。


今天看到一篇文章,终于解决了我的问题,参考:http://fatkun.com/2011/04/org-hibernate-nonuniqueobjectexception.html


这篇文章里面说到:1.不要重新new一个对象,使用load的对象对他进行更改值。


所以最后我把从Hibernate获取到的对象直接进行删除,不new一个对象出来转换了,这样就可以成功删除了。