用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错误的更多相关文章

  1. 报错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; ...

  2. 解决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 ...

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

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

  5. 报错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 ...

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

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

  8. 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更新数据库时出错!

  9. 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" ...

随机推荐

  1. The J2EE Architecture

  2. JS点击2

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. @Conditional系列注解例子

    1. @Conditional 说明:指定的Condition实现类,matches方法返回true则注入bean,false则不注入 @Configuration public class Bean ...

  4. Replication Controller、Replica Set

    假如我们现在有一个Pod正在提供线上的服务,我们来想想一下我们可能会遇到的一些场景: 某次运营活动非常成功,网站访问量突然暴增 运行当前Pod的节点发生故障了,Pod不能正常提供服务了 第一种情况,可 ...

  5. php 即点即改

    html代码 <td><span id="list_order">{$vo.list_order}</span> </td> < ...

  6. 阿里云重磅推出物联网设备身份认证Link ID²

     2018年12月19日,阿里云宣布推出新版物联网设备身份认证Link ID²及物联网安全运营中心Link SOC,护航万物智联.   随着越来越多的设备连接到网络中,随之而来的安全问题越来越突出. ...

  7. PHP PDO 大对象 (LOBs)

    应用程序在某一时刻,可能需要在数据库中存储"大"数据. "大"通常意味着"大约 4kb 或以上",尽管某些数据库在数据达到"大&q ...

  8. 帝国cms简介显示转义字符问题

    在模板中设置简介截取字数为0,前端显示用css控制即可 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 也可以 1,在后 ...

  9. php的字符串{}选定与{变量}

    $str = "abcdefg"; echo $str{2};//输出c $a = "test"; echo "ddd{$a}";//输出d ...

  10. TopCoder[SRM587 DIV 1]:ThreeColorability(900)

    Problem Statement      There is a H times W rectangle divided into unit cells. The rows of cells are ...