可能重复:
Hibernate: different object with the same identifier value was already associated with the sessionHibernate中是否有覆盖函数会覆盖会话中具有相同标识符的对象? (未合并())
我有Hibernate的一个问题:
我有下面的类:人
我从服务器端的数据库中加载特定的Person.class“A”。 然后我通过一个JSP页面将这个对象呈现给客户端。
客户端操纵“A”到“B”,并且然后经由形式将其发送回。我将服务器端的Person.class“B”对象加载到一个新变量中,然后尝试存储它。
但作为整个应用程序是基于会话我不能简单地调用:
HibernateTemplate.saveOrUpdate("B");
相反,我必须在保存前合并“B”与“A”。
但是,当我打电话
HibernateTemplate.merge("B");
的“B”的对象仍然得到“A”,我不希望再存储的所有属性。我希望“B”完全替换“A”对象,而不通过合并它们来获得某些“A”属性。
所以我的问题是:
有没有在Hibernate中的任何“覆盖”或“替换”功能,可以覆盖所有会话中的其中有一个特定对象的属性相同标识符的对象?
(在这个例子中,从形式返回的对象“B”)
还应防止休眠的抱怨:
Exception in thread "main" org.hibernate.NonUniqueObjectException: a
different object with the same identifier value was already associated
with the session:
我不知道我的理解。如果你想更换B A,则只需从数据库中删除,并添加B. – 2012-07-25 14:04:01
,谢谢,我已经这样做了previos我明确的解决方案。那也可以起作用。 – ndrizza 2012-07-25 16:15:36