identifier of an instance of was altered from xxx to xxx问题解决
DeviceRepair是一个类,Device是DeviceRepair的属性,修改DeviceRepair.Device的时候报错:identifier of an instance of was altered from xxx to xxx
@Transactionalfun updateRepair(deviceRepair: DeviceRepair,request: DeviceRepairUpdateRequest):DeviceRepair{val existDeviceId = deviceRepair.device?.idval newDeviceId = request.deviceId ?: throw BadRequestException("deviceId不能为空")if (existDeviceId != newDeviceId){val result = this.deviceMapper.searchRepair(deviceIdIn = setOf(newDeviceId))if(result?.size != 0) {throw BadRequestException("该设备已报修")}else{deviceRepair.device?.id = newDeviceId}}deviceRepair.device = newDeviceId?.let{ this.find(it) }return this.repairRepository.save(deviceRepair)}
此处报错原因是因为else语句中,给DeviceRepair的Device赋值了新的id,Hibernate会报错。
解决办法:
删除else中的操作
直接将新的Device放入DeviceRepair中就可以
@Transactionalfun updateRepair(deviceRepair: DeviceRepair,request: DeviceRepairUpdateRequest):DeviceRepair{val existDeviceId = deviceRepair.device?.idval newDeviceId = request.deviceId ?: throw BadRequestException("deviceId不能为空")if (existDeviceId != newDeviceId){val result = this.deviceMapper.searchRepair(deviceIdIn = setOf(newDeviceId))if(result?.size != 0) {throw BadRequestException("该设备已报修")}}deviceRepair.device = newDeviceId?.let{ this.find(it) }return this.repairRepository.save(deviceRepair)}
}
identifier of an instance of was altered from xxx to xxx问题解决相关推荐
- identifier of an instance of was altered from to n
错误使用场景 public int receiveDogInfo(Dog dog) {dog.setIsMarked("1");dog.setSource("0" ...
- identifier of an instance of was altered from to null
Hibernate的提示错误 Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alte ...
- 【解决Hibernate异常 identifier of an instance of xxx(实体类) was altered from xxx to xxxPK】
org.hibernate.HibernateException:identifier of an instance of xxx(实体类) was altered from xxx to xxxPK ...
- JPA:identifier of an instance of (entity )was altered from 数字 to null;
项目场景: 报错如下 identifier of an instance of com.pcitc.swm.pm.SolidWasteStorRec was altered from 4 to nul ...
- identifier of an instance of xxx was altered from 1 to 1
今天测试一个项目,这个项目使用了hibernate和spring,报错信息如下: org.springframework.orm.hibernate4.HibernateSystemException ...
- HibernateException: identifier of an instance of
org.hibernate.HibernateException: identifier of an instance of 项目的包名was altered from XXX(id) to XXX( ...
- identifier of an instance of 错误
场景 当以查询的实体或者是查询的实体作为参数传送时,修改内容,就会报identifier of an instance of 的错误.持久层工具本人使用的是JPA, private Result fu ...
- identifier of an instance was altered from XXXX to XXXX解决
标题问题出现的可能比较多,现在将原因及解决办法汇总如下: 例子1: 因为实体类中id的属性和hbm.xml配置文件中id的属性不一致造成的 实体类中的id属性是: Java代码 public c ...
- 异常:identifier of an instance of cn.ebank.pojo.News was altered from 2 to 2;
原因: <id name="id" type="java.lang.Integer"> <column name=&q ...
最新文章
- ORACLE JET BASIC TABLE
- [LeetCode]题解(python):013-Roman to Integer
- pwn学习总结(二) —— 基础知识(持续更新)
- python查找指定字符所在行号_python查找字符串中某个字符
- 【转】jquery 注册事件的方法
- shiro框架@RequiresPermissions 解释
- OxA6可以作为C语言常量吗,淮阴师范学院期末考试c语言题库
- [黑金原创教程] FPGA那些事儿《设计篇 I》- 图像处理前夕
- GD32上SFUD万能Flash驱动移植
- HTTP请求详细过程
- 给想去阿里面试的同学一些意见
- Geek生活--netHack
- (转)Java面试笔试题大汇总(最全+详细答案)
- g++ 编程初窥门径
- 前端学习之HTML入门
- oracle数据库恢复aul_ORACLE恢复神器之ODU/AUL/DUL
- 普及计算机知识的意义,计算机在当今社会的重要性
- PSINS源码test_SINS_DR解析
- setContentView剖析
- 哈工大计算机网络Week0-概述