解决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;
    }
时间: 2024-10-31 13:27:46

解决a different object with the same identifier value was already associated with the session错误的相关文章

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

NonUniqueObjectException 解决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 already associated with the session:

hibernate中一种导致a different object with the same identifier value was already associated with the session错误方式及解决方法

先将自己出现错误的全部代码都贴出来: hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-con

org.hibernate.NonUniqueObjectException: 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 already associated with the session异常解决办法 为什么还会说已经存在相同的session了呢.然后每次将项目重启后第一次编辑的时候问题不会触发,只有当第二次操作的时候才会出现这个问题. 解决办法:关闭session.好好检查操作完成后有没有关闭会话. org.hibernat

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

错误提示: org.springframework.dao.DuplicateKeyException: a different object with the same identifier value was already associated with the session: [cn.itcast.bos.domain.User#4]; nested exception is org.hibernate.NonUniqueObjectException: a different obj

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

2017-3-16 我使用SSH框架在做单表CRUD的更新操作时遇到了一个问题,就是页面间该怎么传值?解决该需求时引发了一系列的bug,趁还记得好好总结一番. 前端页面间传值 情景:在我查出所以记录后,点击修改会链接到新的修改页面. 问题:该新页面没有之前的实体信息,该如何传递要修改的实体信息给该页面,例如id? 思路1:利用struts的action来传值. 1 <form action="deleteSerCate.action" method="post"

Hibernate更新数据报错:a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]

使用hibernate更新数据时,报错 Struts has detected an unhandled exception: Messages: a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001] a different object w

org.hibernate.TransientObjectException:The given object has a null identifier

1.错误描述 org.hibernate.TransientObjectException:The given object has a null identifier:com.you.model.UserInfo 2.错误原因 3.解决办法

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread---------程序报错

今天遇到了这个问题: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:-- 找其原因是因为同一个object,如一个person在seession里保存了一份,而增加的别的object,如company的时候,由于做了关联关系,从数据库里又get了一个person,而这个person和s

The given object has a null identifier解决之法

<input type="hidden" name="memberPermission.id"????????????value="${memberpermission.id}"> <input type="hidden"????????????name="memberPermission.mtid" value="${memberpermission.mtid}"&g