修改公寓楼栋报错:JPA hibernate 异常 id变更报错。identifier was altered

org.springframework.orm.jpa.JpaSystemException: identifier of an instance of com.thinkgem.jeesite.modules.sys.entity.Office was altered from 151 to 404; nested exception is org.hibernate.HibernateException: identifier of an instance of com.thinkgem.jeesite.modules.sys.entity.Office was altered from 151 to 404

@Transactional(readOnly=false)
public void save(Room room) {
roomRepository.clear();
roomRepository.save(room);
}

org.springframework.orm.jpa.JpaSystemException: identifier of an instance of com.thinkgem.jeesite.modules.sys.entity.Office was altered from 151 to 404; nested exception is org.hibernate.HibernateException: identifier of an instance of com.thinkgem.jeesite.modules.sys.entity.Office was altered from 151 to 404

由于缓存了变更之前的id,因此在做修改操作时,清空下balaTruckDao.clear();

@Transactional(readOnly = false)
public void save(BalaTruck balaTruck) {
//office.id变更导致hibernate持久化异常因为一级缓存保存了修改之前的office.id。用clear清除session
balaTruckDao.clear();
//保存时,前端传入机构id,使用officeDao带出机构code,再持久化保存
balaTruck.setTruckOwnCode(officeDao.findOne(balaTruck.getTruckOwnCode().getId()));
balaTruckDao.save(balaTruck);}


作者:olight
来源:CSDN
原文:https://blog.csdn.net/olight/article/details/71195101

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值