【发布时间】:2011-03-16 23:56:49
【问题描述】:
更改实体的@id 后来自
@Id
private int getId(){
return this.id;
}
到
@Id
private String getLogin(){
return this.login;
}
我得到错误:
a different object with the same identifier
value was already associated with the session
在 web 应用程序中没有改变任何东西。读取实体,然后更改表单中的某些字段,然后在提交后我尝试保存或更新实体。使用int 作为@Id 没有问题,但现在使用String 作为@Id 我通过更新或保存实体得到上述错误:
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void saveOrUpdate(User u) {
getHibernateTemplate().saveOrUpdate(u);
}
可能是什么问题?
【问题讨论】:
-
在会话中显示代码可能会有所帮助。
标签: hibernate spring annotations entity validates-uniqueness-of