update时候出现如下错误
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
解决方法:
根据id得到缓存里的pojo对象,修改该对象,更新该对象
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
解决方法:
根据id得到缓存里的pojo对象,修改该对象,更新该对象
public void update(AppInfo appInfo){
AppInfo ai = getAIById(appInfo.getId());
ai.setAct(appInfo.getAct());
ai.setApp_name(appInfo.getApp_name());
ai.setApp_id(appInfo.getApp_id());
ai.setInstall_ram_range(appInfo.getInstall_ram_range());
ai.setPackage_name(appInfo.getPackage_name());
ai.setSwitch_ram_range(appInfo.getSwitch_ram_range());
Transaction ts = s.beginTransaction();
s.update(ai);
ts.commit();
}
本文介绍了解决在使用Hibernate框架更新数据时遇到的NonUniqueObjectException异常的方法。通过获取缓存中的对象并直接修改该对象的方式避免了异常的发生。
3145

被折叠的 条评论
为什么被折叠?



