a different object with the same identifier value was already associated with the session

鱼满舱

关注

阅读 46

2023-09-07


数据库更新记录报错:

a different object with the same identifier value was already associated with the session: [com.miracle.dm.sysmgr.user.model.OrgUserProInfo#4028800b269cc2f301269cc959960007]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.miracle.dm.sysmgr.user.model.OrgUserProInfo#4028800b269cc2f301269cc959960007]

临时解决办法:

在update之前先调用:  this.getHibernateTemplate().getSessionFactory().getCurrentSession().clear();

 

网上另有解决方法:

把数据访问层的更新方法中的update 改成merge就可以实现

public void update(Role r) {
  getHibernateTemplate().update(r);
 }
  
public void update(Role r) {
  getHibernateTemplate().merge(r);
 }

精彩评论(0)

0 0 举报