entityManager.persist(user)-> javax.persistence.EntityExistsException:User @ b3089已经是持久的 [英] entityManager.persist(user) -> javax.persistence.EntityExistsException: User@b3089 is already persistent
本文介绍了entityManager.persist(user)-> javax.persistence.EntityExistsException:User @ b3089已经是持久的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// lookup existing user & set a currently null child entity (ContactInfo)
user.setContactInfo(contactInfo);
// update the user in the datastore with newly created child Entity
entityManager.persist(user);
产生异常:
javax.persistence.EntityExistsException: User@b3089 is already persistent
由于用户已经存在,除了entityManager.persist
之外,我还有其他方法可用于更新而不是插入吗?
Since the user already exists, is there some other method besides entityManager.persist
that I should be using for an update instead of an insert?
推荐答案
您的user
实例已经在持久性上下文中加载,只需对其进行修改,并且不要调用任何EntityManager
方法,JPA提供程序将在刷新或提交时自动更新数据库.
Your user
instance is already loaded in the persistence context, just modifiy it and don't invoke any EntityManager
method, the JPA provider will automatically update the database at flush or commit time.
这篇关于entityManager.persist(user)-> javax.persistence.EntityExistsException:User @ b3089已经是持久的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文