解决a different object with the same identifier value was already associated with the session错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决a different object with the same identifier value was already associated with the session错误相关的知识,希望对你有一定的参考价值。

20:41:15

  今天做一个saveorupdate操作报错: 

 org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [com.xshcar.carcloud.entity.UboxTbl#1291]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.xshcar.carcloud.entity.UboxTbl#1291] 

一个经典的hibernate错误:a different object with the same identifier value was already associated with the session xxxx
hibernate3.0以上使用merge()来合并两个session中的同一对象  

解决:

在daoimpl层调用hibernate的getHibernateTemplate().merge(对象)方法;

public boolean executeUpdate(T t) {
        boolean b=true;
        try {
       t=(T)this.getHibernateTemplate().getSessionFactory().getCurrentSession().merge(t);
            getHibernateTemplate().update(t);
        } catch (DataAccessException e) {
            e.printStackTrace();
            b=false;
        }
            
        return b;
    }

 

 
 
 
 
 

以上是关于解决a different object with the same identifier value was already associated with the session错误的主要内容,如果未能解决你的问题,请参考以下文章

a different object with the same identifier value was already associat

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

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread

利用struts进行前端页面间传值及hibernate异常:a different object with the same identifier value was already associat

Hibernate更新数据报错:a different object with the same identifier value was already associated with the se

hibernate中一种导致a different object with the same identifier value was already associated with the sess