码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-06-28 21:44:36      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

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错误

标签:

原文地址:http://www.cnblogs.com/ZC987053660/p/5624969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!