JPA hibernate 异常 id变更报错。identifier was altered

xiaoxiao2021-02-28  131

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); }
转载请注明原文地址: https://www.6miu.com/read-23813.html

最新回复(0)