在使用hibernate框架里面的:saveOrUpdate报错:

意思就是另一个对象的id(id同值)已经被session关联了。

原因分析:

在第1步中中通过titleList.get(0)获取一个对象duty1,在第2步中将duty的dutyId设置成duty1的dutyId,而duty1本来就是存在一级缓存session里面的,在第3步时saveOrUpdate(duty)相当于内存中存在两个dutyId一样的对象,因此抛出异常。

解决方法:

如果dao或Service类继承了HibernateDaoSupport,可以调用this.getHibernateTemplate().clear();清除session(的关联)。

如图中的第二步添加了:this.getHibernateTemplate().clear();

org.springframework.dao.DuplicateKeyException: a different object with the same identifier value was的更多相关文章

  1. org.springframework.dao.DuplicateKeyException: 问题

    转自:https://blog.51cto.com/chengxuyuan/1786938 org.springframework.dao.DuplicateKeyException: a diffe ...

  2. org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案

    异常信息: org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identi ...

  3. org.springframework.dao.DuplicateKeyException

    org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [insert into account v ...

  4. java.lang.RuntimeException: org.springframework.dao.DuplicateKeyException:

    java.lang.RuntimeException: org.springframework.dao.DuplicateKeyException: ### Error updating databa ...

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

    public Wcrash getWcrashInfo(int id) { String sql = "select plateform_id,android_version,app_ver ...

  7. 【异常】Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException

    Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException ...

  8. org.springframework.dao.DataIntegrityViolationException:

    数据库用的hibernate,开发工具用的myeclipse,使用开发工具连接数据库生成hibernate基于xml的po类,运行时报org.springframework.dao.DataInteg ...

  9. javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

随机推荐

  1. HBase-MR

    一.需求1:对一张表的rowkey进行计数 官方HBase-Mapreduce 需求1:对一张表的rowkey进行计数 1)导入环境变量 export HBASE_HOME=/root/hd/hbas ...

  2. 【我的Android进阶之旅】解决Center OS 64位系统编译Android APP报错error=2和finished with non-zero exit value 127

    一.错误描述 1.问题 java.io.IOException: error=2, 没有那个文件或目录 今天在刚重新搭建好的64位的Center OS上安装好了Android SDK,Jenkins, ...

  3. 软件project--作图

    软工学习进行了一个多月,但是真正静下心来学习也只是一周左右吧,这段时间里给自己印象最深刻的就是作图了, 机房收费系统我们是先进行的编码,后学习软件project对它来了一次回想性的文档编写. 刚開始当 ...

  4. Spark Streaming实战

    1.Storm 和 SparkStreaming区别 Storm                      纯实时的流式处理,来一条数据就立即进行处理 SparkStreaming 微批处理,每次处理 ...

  5. springboot使用tomcat apr模式

    因需项目对并发要求比较高.提高Tomcat效率.使用tomcat apr模式.今天在这记录下使用过程.apr全称为apache portable runtime.这里套用下wiki对apr的解释. T ...

  6. [golang note] 数组切片

    数组 √ golang数组包含的每个数据称为数组元素(element),数组包含的元素个数被称为数组长度(length). √ golang数组的长度在定义后不可更改,并且在声明时可以是一个常量或常量 ...

  7. 网络爬虫Java实现抓取网页内容

    package 抓取网页; import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream; ...

  8. [笔记] Ubuntu 18.04安装cuda 10及cudnn 7流程

    安装环境 OS:Ubuntu 18.04 64 bit 显卡:NVidia GTX 1080 任务:安装 CUDA 10及cuDNN 7 工具下载 NVidia官网下载下列文件: CUDA 10:cu ...

  9. PKU 1521 Entropy(简单哈弗曼树_水过)

    题目大意:原题链接 给你一个字符串,首先是计算出一个按正常编码的编码长度,其次是计算出一个用霍夫曼编码的编码长度,最后求正常编码的长度除以霍夫曼编码长度的比值,保留一位小数. 解题思路:需要知道 1. ...

  10. Oracle中验证非空的函数NVL(),NVL2()总结

    1.NVL()函数 NVL函数的格式如下: NVL(expr1,expr2) 含义是:如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值. 2 N ...