在使用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. apache2.2版本 configuration error: couldn't perform authentication. AuthType not set!: /

    configuration error:  couldn't perform authentication. AuthType not set!: /  500服务器错误 解决方案: <Dire ...

  2. 【react npm】解决用npmstart启动别人的react项目的问题1:sha1-xxx checksum failed wanted sha1-xxx but got sha512-xxx. (10700 bytes)

    1.npm是nodejs的包管理器,相当于php的composer,python的pip,用于安装各种包. 2.一般来说,别人拷给你的react项目不会带依赖包的,因为太大了,需要用npm命令自己安装 ...

  3. Robberies---hdu2955(概率dp,01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 题目给了每个银行的钱和被抓的概率,由于要抢尽量多的钱,所以要保证尽量不被抓,而抢多个银行之后不被 ...

  4. go学习笔记二:运行使用命令行参数

    本文只作为博主的go语言学习笔记. 对命令行参数的解析,只是在运行时使用的,比如以下命令:go run gomain -conf conf.toml 没有办法再go build时使用. 一.运行时命令 ...

  5. spring 自定义事物同步器(一): TransactionSynchronizationManager 解析

    一..JPA 获取 Hibernate的session try { session = entityManager.unwrap(Session.class); } catch (Exception ...

  6. postman 断言

    //断言 pm.test("message等于'操作成功'", function () { var jsonData = pm.response.json(); console.l ...

  7. img 标签注意 默认img标签,有一个1px的边框 img{ border: 0; }

    默认img标签,有一个1px的边框 img{ border: 0; }

  8. mongoDb,下载及启动

     mongoDb下载 https://www.mongodb.com/download-center 可视化工具Robomongo下载 https://robomongo.org/download m ...

  9. 二进制x&(x-1);

    求下面函数的返回值(微软) int func(x) {     int countx = 0;     while(x)     {           countx ++;           x ...

  10. APP移动端自动化测试工具选型“兵器谱”一览(主流开源工具)

    (下面大多数工具都是开源工具,在github,码云等开源平台都能找到) "测试那点事儿”在看到360旗下的测试团队整理的关于目前APP移动端自动化相关的工具,觉得总结的很到位,对目前大多数中 ...