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