// 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
之外还有其他方法我应该用于更新而不是插入吗?
最佳答案
您的 user
实例已经加载到持久性上下文中,只需修改它并且不要调用任何 EntityManager
方法,JPA 提供程序将在刷新或提交时自动更新数据库。
关于java - entityManager.persist(用户) -> javax.persistence.EntityExistsException : User@b3089 is already persistent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3527398/