identifier of an instance of xx.entity was altered from xxKey@249e3cb2 to xxKey@74e8f4a3; nested exception is org.hibernate.HibernateException: identifier of an instance of xxentity was altered from错误
用entityManager保存数据时报错如下
identifier of an instance of xx.entity was altered from xxKey@249e3cb2 to xxKey@74e8f4a3; nested exception is org.hibernate.HibernateException: identifier of an instance of xxentity was altered from xxKey@249e3cb2 to xxKey@74e8f4a3
一共存了三张表的数据,使用了事务,前面两张表存各存1条数据,最后一张表存两条数据。执行完成后报上面的错误。后来把最后一张表实体上的联合主键去掉不报错,但最后一张表只保存成功1条数据
太奇怪了。怀疑是事务引起,检查了是使用的
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
写了单元测试,单独插入最后一张表两条数据可以成功插入。
最后找到问题关键,是因为最后一张表的其中一条数据是从数据库里读取出来的,另外一条是新插入的。把读取的数据copy到新new的实体后问题解决。
原因分析 处于Persistent状态的实体的id, hibernate是不允许修改后双保存回去。
identifier of an instance of xx.entity was altered from xxKey@249e3cb2 to xxKey@74e8f4a3; nested exception is org.hibernate.HibernateException: identifier of an instance of xxentity was altered from错误的更多相关文章
- 报错HTTP Status 500 - HHH000142: Javassist Enhancement failed: cn.itcast.entity.Customer; nested exception is org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: cn.itcast.entity.
报错 type Exception report message HHH000142: Javassist Enhancement failed: cn.itcast.entity.Customer; ...
- 解决org.hibernate.HibernateException: identifier of an instance of com.ahd.entity.Order was altered from2 to 0
错误信息 严重: Servlet.service() for servlet [springmvc] in context with path [/order] threw exception [Re ...
- 【hibernate】错误:org.hibernate.HibernateException: identifier of an instance of com.agen.entity.Monthdetail was altered from xx to xx
所报错误: org.hibernate.HibernateException: identifier of an instance of com.agen.entity.Monthdetail was ...
- Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alterde from
Caused by: org.hibernate.HibernateException: identifier of an instance of ... is alterde from Hi ...
- 报错HTTP Status 500 - The given object has a null identifier: cn.itcast.entity.Customer; nested exception is org.hibernate.TransientObjectException: The given object has a null identifier:
在使用模型驱动封装的时候,要保证表单中name属性名和类中属性名一致,否则将会报错如下: HTTP Status 500 - The given object has a null identifie ...
- org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: 的解决方案
1.错误信息 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist ...
- spring 整合hibernate注解时候,出现“Unknown entity: com.ssh.entry.Admin; nested exception is org.hibernate.MappingException: Unknown entity: com.ssh.entry.Admin”异常的问题
今天学习使用ssh框架的时候,出现一个异常,弄了好久才找到,在这记录一下,我的sb错误1.spring整合hibernate,取代*.hbm.xml配置文件 在applicationContext ...
- Exception occurred during processing request: The given object has a null identifier: com.zsn.crm.Model.SaleVisit; nested exception is org.hibernate.TransientObjectException: The given object has a nu
edit.jsp页面没有加入隐藏字段 id ,导致模型驱动封装时缺少id ,,调用update更新数据库时出错!
- org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:
详细错误堆栈信息: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" ...
随机推荐
- 反编译字节码角度分析synchronized关键字的原理
1.synchronized介绍 synchronized是java关键字.JVM规范中,synchronized关键字用于在线程并发执行时,保证同一时刻,只有一个线程可以执行某个代码块或方法:同时还 ...
- boost 大小端转换
boost 中有一个edmian 里面有转换函数模板 native_to_little<T> 本地转换为小端 native_to_bit<T> 本地转换为大端
- 笔记44 Hibernate快速入门(一)
一.Hibernate简介 Hibernate 是传统 Java 对象和数据库服务器之间的桥梁,用来处理基于 O/R 映射机制和模式的那些对象. Hibernate 架构是分层的,作为数据访问层,你不 ...
- vue组件基础之创建与使用
一.创建组件 <script src="vue.js"></script> <!--引入vue.js文件--> <div id=" ...
- ajax 工作原理
Ajax的优缺点及工作原理? 定义和用法: AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML).Ajax 是一种用于创建快速动态网 ...
- notepad++去换行(简单、快捷)
文本处理问题 这个方式可以快捷处理, 不用Linux命令, linux 与window之间的文件转换很烦人, 这个方法可以处理
- leetcode-第11场双周赛-5089-安排会议日程
题目描述: 自己的提交: class Solution: def minAvailableDuration(self, slots1: List[List[int]], slots2: List[Li ...
- JAVA单线程和多线程的实现方式
1.java单线程的实现 一个任务一个人独立完成 public class SingletonThread { @SuppressWarnings("static-acce ...
- 用jQuery实现鼠标移动切换图片动画
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- redis和redis php扩展安装
redis的源码安装 wget http://download.redis.io/redis-stable.tar.gz tar -zxvf redis-stable.tar.gz cd redis- ...