zoukankan      html  css  js  c++  java
  • s2sh保存错误: a different object with the same identifier value was already associated


    org.springframework.orm.hibernate3.HibernateSystemException:
              a different object with the same identifier value was already associated with the session: [com.demo.bean.Option]

    因为在hibernate中同一个session里面有了两个相 同标识但是是不同实体,当这时运行saveOrUpdate(object)操作的时候就会报这个错误。解决方法是:
    hibernate3.0以上使用merge()来合并两个session中的同一对象:
    public void attachDirty(Role instance) {
            log.debug("attaching dirty Role instance");
            try {
               instance = hibernateTemplate.merge(instance);
                hibernateTemplate.saveOrUpdate(instance);
                log.debug("attach successful");
            } catch (RuntimeException re) {
                log.error("attach failed", re);
                throw re;
            }
        }

  • 相关阅读:
    Android 控件的学习
    Java并发编程
    Glide的学习之路
    插件化和热修复学习之路
    OkHttp的学习
    WMS的学习
    app一点一滴的学习
    进程启动学习
    View学习之解决滑动冲突
    应用学习
  • 原文地址:https://www.cnblogs.com/summer520/p/2964263.html
Copyright © 2011-2022 走看看