保存对象报错with two open Sessions

purorderService.save(newpur);
出现如下

org.springframework.orm.hibernate3.HibernateSystemException: illegally attempted to associate a proxy with two open Sessions;

nested exception is org.hibernate.HibernateException: illegally attempted to associate a proxy with two open Sessions

解决方法:

更换方法:purorderService.saveMerge(newpur);

illegally attempted to associate a proxy with two open Sessions
在session缓存中以两个标识相同的对象
使用merge方法
merge方法在执行之前都回去缓存中找是不是有相应的记录,也就是会有一条select语句,执行改语句的目的是为了判断该对象是否被修改了。而update就不管这些,直接就一条update语句。

原文地址:https://www.cnblogs.com/mangwusuozhi/p/9565476.html