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问题解决相关推荐

  1. identifier of an instance of was altered from to n

    错误使用场景 public int receiveDogInfo(Dog dog) {dog.setIsMarked("1");dog.setSource("0" ...

  2. identifier of an instance of was altered from to null

    Hibernate的提示错误 Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alte ...

  3. 【解决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 ...

  4. 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 ...

  5. identifier of an instance of xxx was altered from 1 to 1

    今天测试一个项目,这个项目使用了hibernate和spring,报错信息如下: org.springframework.orm.hibernate4.HibernateSystemException ...

  6. HibernateException: identifier of an instance of

    org.hibernate.HibernateException: identifier of an instance of 项目的包名was altered from XXX(id) to XXX( ...

  7. identifier of an instance of 错误

    场景 当以查询的实体或者是查询的实体作为参数传送时,修改内容,就会报identifier of an instance of 的错误.持久层工具本人使用的是JPA, private Result fu ...

  8. identifier of an instance was altered from XXXX to XXXX解决

    标题问题出现的可能比较多,现在将原因及解决办法汇总如下: 例子1:  因为实体类中id的属性和hbm.xml配置文件中id的属性不一致造成的 实体类中的id属性是: Java代码   public c ...

  9. 异常: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 ...

最新文章

  1. ORACLE JET BASIC TABLE
  2. [LeetCode]题解(python):013-Roman to Integer
  3. pwn学习总结(二) —— 基础知识(持续更新)
  4. python查找指定字符所在行号_python查找字符串中某个字符
  5. 【转】jquery 注册事件的方法
  6. shiro框架@RequiresPermissions 解释
  7. OxA6可以作为C语言常量吗,淮阴师范学院期末考试c语言题库
  8. [黑金原创教程] FPGA那些事儿《设计篇 I》- 图像处理前夕
  9. GD32上SFUD万能Flash驱动移植
  10. HTTP请求详细过程
  11. 给想去阿里面试的同学一些意见
  12. Geek生活--netHack
  13. (转)Java面试笔试题大汇总(最全+详细答案)
  14. g++ 编程初窥门径
  15. 前端学习之HTML入门
  16. oracle数据库恢复aul_ORACLE恢复神器之ODU/AUL/DUL
  17. 普及计算机知识的意义,计算机在当今社会的重要性
  18. PSINS源码test_SINS_DR解析
  19. setContentView剖析
  20. 哈工大计算机网络Week0-概述

热门文章

  1. android-studio安装过程详解
  2. 图像处理冷知识——dpi和ppi
  3. python 标准差计算(std)
  4. IDEA 2021 没有Allow parallel run
  5. 使用Metasploit对MSSQL渗透测试步骤——学习笔记
  6. Android仿斗鱼滑动登录验证
  7. Markdown教程笔记(含印象笔记语法)
  8. 万字长文带你解读Linux
  9. Linux创建模板封装虚拟机
  10. 华为云弹性公网IP服务,为企业敲开互联网大门