首页 > 其他 > 详细

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

时间:2016-06-28 21:44:32      阅读:658      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!