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" ...
随机推荐
- projects
layout title project 开源项目 本文记录我收藏的开源项目
- Linux/CentOS 7 timezone 修改
1.su - 登录root用户 2.timedatectl set-timezone {timezone} (set后面加想要设置的时区) 举例:timedatectl set-timezone As ...
- set -x 调试shell
在上面的结果中,前面有“+”号的行是shell脚本实际执行的命令,前面有“++”号的行是执行trap机制中指定的命令,其它的行则是输出信息. shell的执行选项除了可以在启动shell时指定外,亦可 ...
- Linux如何删除特殊字符文件名或目录?
通过文件的inode号删除文件 先用ls -i 找出要删除文件的inode 号 2ls -i |grep xxxxxx|awk '{print $2}'|xargs -i rm -f {} xxxxx ...
- JUC 一 线程池
线程 线程,是程序执行的最小单元.线程是进程中的其中一个实体,是被系统独立调度和分派的基本单位 它可与同属一个进程的其它线程共享进程所拥有的全部资源. 一个线程可以创建和撤消另一个线程,同一进程中的多 ...
- Python 空值和非空值
1)任何值为0的值都是false,任何非0的值都是true if -0.0: print 'yes' #不打印yes if -0.1: print 'yes' #打印yes 2)任何为空的值都是fla ...
- Delphi提取EXE,DLL文件图标
//uses ShellAPIprocedure TForm1.Button1Click(Sender: TObject);var IconIndex:Word; h:hICON;begin Icon ...
- 下面是一段delphi代码,你在c# 中引入api 即可
procedure TForm1.Button1Click(Sender: TObject);var i:HWND; cs:CREATESTRUCT;begin// i := FindWindowEx ...
- xcode5 添加Build Phases脚本
http://www.runscriptbuildphase.com/ 版权声明:本文为博主原创文章,未经博主允许不得转载.
- KiFastCallEntry() 机制分析
1. 概述 从 windows xp 和 windows 2003 开始使用了快速切入内核的方式提供系统服务例程的调用. KiFastCallEntry() 的实现是直接使用汇编语言,C 语言不能直接 ...