在用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. SolidWorks装配体

  2. 《玩转spring全家桶》学习笔记-------------丁雪丰

    一.spring 课程介绍 1.初识spring 2.数据操作 3.web开发 4.spring boot 5.spring cloud 二.初识spring Spring Boot.Spring C ...

  3. Mergeable Stack ZOJ - 4016(list)

    ZOJ - 4016 vector又T又M list是以链表的方式存储的 是一个双向链表 元素转移操作中,不能一个个遍历加入到s中,list独有的splic函数可以在常数时间内实现合并(并删除源lis ...

  4. 【CTSC2016】时空旅行

    链接 http://uoj.ac/problem/198 题解 首先要发现答案要我们求这个式子: \[ ans=min\bigl((x_i-x)^2+c_i\bigr) \] 显而易见的是这种时空嫁接 ...

  5. H3C WAP712C 路由器设置

    0.做完任何设置之后都要执行保存操作,否则断电后设置会丢失! 1.默认登录参数:IP:192.168.0.50ID:adminPD:h3capadmin 2.修改默认IP地址:设备 --> 接口 ...

  6. CF集萃2

    CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...

  7. 配置webpack.config.js中的文件

    webpack.config.js文件中,主要包括 entry:入口文件 output:出口文件 module:模块 plugins:插件 这几部分 1.基本配置 运行 webpack 这一命令可以将 ...

  8. boto3库限速

    # -*- coding: utf-8 -*- import boto3 from boto3.s3.transfer import TransferConfig # from s3transfer. ...

  9. seq2seq

    seq2seq: seq2seq就是将输入序列经过encoder-decoder变成目标序列. 如图所示,输入序列是 [A, B, C, <EOS>],输出序列是  [W, X, Y, Z ...

  10. MarkDown里面的Emoji表情

    我才发现MarkDown里面可以使用一些Emoji表情,好玩,以后写博客的趣味性大大增加 想看全部的就去这里找https://www.webfx.com/tools/emoji-cheat-sheet ...