在用hibernate getSession().save(entity)方法保存数据库表实体类的时候报这个异常

我的需求是一个请求要往数据库表插两条数据,根据传值判断做了for循环调两次save()方法

但是第二次会报异常,因为我的for循环用到了同一个实体类对象,只是在第二次循环的时候对实体类对象属性做了更改,这是不允许的。

解决办法也比较简单,循环的时候创建新的对象,两次循环往save方法传的参数不是同一个实体类对象就可以了。

session.clear()也可以,只要clear前后实体对象属性不丢值,满足需求就行。

identifier of an instance of **** was altered from **** to *****的更多相关文章

  1. JPA:identifier of an instance of was altered from

    由于前台提交的对象,并没有关联对象的数据. 所以要把关联对象赋值一下,在合并集合. WmsOutboundreport entity2 = service.findOne(item.getOutbou ...

  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. identifier of an instance of com.xxx.model.system.xxxObject was altered from 1765 to 1766

    Caused by: org.hibernate.HibernateException: identifier of an instance of com.xxx.model.system.xxxOb ...

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

  6. 161117、使用spring声明式事务抛出 identifier of an instance of

    今天项目组有成员使用spring声明式事务出现下面异常,这里跟大家分享学习下. 异常信息: org.springframework.orm.hibernate3.HibernateSystemExce ...

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

  8. Hibernate异常:identifier of an instance of 错误

    今天写项目时,在使用hibernate封装的插入方法时,由于需要同时保存多个数据,导致出现identifier of an instance of 如下代码 :(由于最大最小分数不同所以需要插入两条数 ...

  9. 从一次异常中浅谈Hibernate的flush机制

    摘自http://www.niwozhi.net/demo_c70_i1482.html http://blog.itpub.net/1586/viewspace-829613/ 这是在一次事务提交时 ...

随机推荐

  1. 文本编辑利器Notepad++ 10个强大而又鲜为人知的特性【转】

    文本编辑利器Notepad++ 10个强大而又鲜为人知的特性 - 为程序员服务

  2. ezdxf包下autocad的开发

    利用 ezdxf 库读写geotiff格式的地形影像方法(InsertRasterToCAD) 包一:dxfgrabber GitHub - mozman/dxfgrabber: Outdated D ...

  3. Docker 命令查询

    Docker — 从入门到实践 Docker 命令查询 基本语法 Docker 命令有两大类,客户端命令和服务端命令.前者是主要的操作接口,后者用来启动 Docker Daemon. 客户端命令:基本 ...

  4. 转载:原来JavaScript的闭包是这么回事!

    相关阅读:https://www.itcodemonkey.com/article/8565.html

  5. pwn-GUESS

    参考了其他wp之后才慢慢做出来的 记录一下 首先checksec一下 有canary 放到IDA看下源码 运行流程大概是 有三个fork 即三次输入机会,于是无法爆破cannary 本题用的是SSP ...

  6. js重点--this关键字

    推荐博客:https://www.cnblogs.com/huaxili/p/5407559.html this是JavaScript的一个关键字,表示的不是对象本身,而是指被调用的上文. 主要用于以 ...

  7. I2C(二) linux2.6

    目录 I2C(二) linux2.6 总线驱动 关键结构 入口 i2c_add_adapter 硬件操作 设备驱动 入口 注册 attach_adapter eeprom_detect i2c_att ...

  8. ArcGIS Editor for Open Street Map 10.X for Desktop下载地址

    ArcGIS Editor for Open Street Map可用于导入从OSM下载的地图,但并不是ArcGIS自带的工具,需要从官网下载,虽然文件很小,但下载速度较慢,易断开. 在此为找不到或不 ...

  9. 【bzoj 4449】[Neerc2015]Distance on Triangulation

    Description 给定一个凸n边形,以及它的三角剖分.再给定q个询问,每个询问是一对凸多边行上的顶点(a,b),问点a最少经过多少条边(可以是多边形上的边,也可以是剖分上的边)可以到达点b. I ...

  10. 分页之 skip(pageindex*(index-1).take(size).Tolist();

    grdView.DataSource = Select().Skip(pageSize * (start - 1)).Take(rows).ToList();这个分页性能上并不高下面是我的分页 1 2 ...