Hibernate 在 saveOrUpdate() NonUniqueObjectException错误

来源:互联网 发布:lol解封软件下载 编辑:程序博客网 时间:2024/05/06 13:55

Hibernate 在 saveOrUpdate() 一个 detached object 时候会报以下错误,
通常是 Web 页面修改和保存后出现

org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [domain.Director#9]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [domain.Director#9]
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [domain.Director#9]

 

if (object.getId() != null) {
    getSession().merge(object);
} else {
    getHibernateTemplate().saveOrUpdate(object);
}

 

觉得这种方法不是很完美,寻找更好的解决方法

修改了Dao实现
原创粉丝点击