修改实体的问题
a different object with the same identifier value was already associated with the session:今天遇到同样的问题,我的场景是主表从表做级联,当同时更新主表与从表时,出现此错误。 从网上查资料,加上自己理解,大概意思是 从表不能取持久化对象去做更新操作。解决后的代码如下,红色字体是从页面取来的值,使用merge()更新到数据库:
HouserEntity t = houserService.get(HouserEntity.class, houser.getId());
InstallationEntity installationPage = this.getInstallationPage(houser, request);
installationPage.setId(t.getInstallationEntity().getId());
MyBeanUtils.copyBeanNotNull2Bean(houser, t);
houserService.saveOrUpdate(t);
installationService.getSession().merge(installationPage);
页:
[1]