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;
            }
        }

  • 相关阅读:
    数据库函数
    数据库查询习题整理(二)
    数据库查询习题整理(一)
    1202数据库查询
    1201新课程TSQL语句
    1123项目第五天
    1121项目第四天
    1120项目第三天
    14
    にちかん
  • 原文地址:https://www.cnblogs.com/summer520/p/2964263.html
Copyright © 2011-2022 走看看