今天遇到个怪问题,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,问题解决。希望对大家有帮助