identifier of an instance of bean was altered from 1 to 2(持久化对象ID变更)

来源:互联网 发布:springmvc ajax json 编辑:程序博客网 时间:2024/05/01 10:36

今天遇到个怪问题,hibernate修改外键id时出现:

org.springframework.orm.hibernate3.HibernateSystemException: identifier of an instance of xx altered from 2677 to 2672; 
nested exception is org.hibernate.HibernateException: identifier of an instance of com.yongjun.tdms.model.CustomerRelationship.contactArchives.ContactArchives altered from 2677 to 2672
Caused by: org.hibernate.HibernateException: identifier of an instance of xx altered from 2677 to 2672
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:51)...at java.lang.Thread.run(Thread.java:619)


结果在网上看到大神的解决方法

引用:

应该是缓存导致,save前先clear()试试dao.clear();dao.save(entity);

自己加了个:

public void storeContractAdditionalInfo(ContractAdditionalInfo ai){super.getHibernateTemplate().clear();//加的清缓存super.store(ai);}

ok,问题解决。希望对大家有帮助
 
阅读全文
0 0