NonUniqueObjectException当存在对象时 [英] NonUniqueObjectException when persist object

查看:112
本文介绍了NonUniqueObjectException当存在对象时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用JPA持久保存一个对象时,我得到 NonUniqueObjectException



我使用persistence的对象有其他对象,



在已经保存在DB中的对象中进行合并是一种可能性,但我只能坚持一个对象(此对象具有所有信息)


$ b


$ b

我可以将任何注释放在我的id上进行合并,当这个id已经保存在MySQL数据库中时

解决方案使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆