NonUniqueObjectException当存在对象时 [英] NonUniqueObjectException when persist object
问题描述
当我使用JPA持久保存一个对象时,我得到 NonUniqueObjectException 。
我使用persistence的对象有其他对象,
在已经保存在DB中的对象中进行合并是一种可能性,但我只能坚持一个对象(此对象具有所有信息)
$ b
$ b
entityManager.merge(..)
或者离开 id
字段为空。否则,hibernate将检查数据库中是否存在具有相同id的实体,如果发现它会失败。 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?
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.
这篇关于NonUniqueObjectException当存在对象时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!