NonUniqueObjectException when persist object

淺唱寂寞╮ 提交于 2019-12-12 03:18:57

问题


I am getting NonUniqueObjectException when i persist an object using JPA.

The object where i make persisent, have other objects and in some cases the objects have the same id.

Make a merge in object where is already saved in DB is a possibility but i only can make persist at one object (this object have all information)

I can put any annotation on my id to make a merge when this id is already saved in MySQL database?


回答1:


Use entityManager.merge(..) or leave the id field empty. Otherwise hibernate will check if an entity exists in the database with the same id and will fail if it finds one.



来源:https://stackoverflow.com/questions/9717399/nonuniqueobjectexception-when-persist-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!