org.springframework.dao.DuplicateKeyException: a different object with the same identifier value was
在使用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的更多相关文章
- org.springframework.dao.DuplicateKeyException: 问题
转自:https://blog.51cto.com/chengxuyuan/1786938 org.springframework.dao.DuplicateKeyException: a diffe ...
- org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案
异常信息: org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identi ...
- org.springframework.dao.DuplicateKeyException
org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [insert into account v ...
- java.lang.RuntimeException: org.springframework.dao.DuplicateKeyException:
java.lang.RuntimeException: org.springframework.dao.DuplicateKeyException: ### Error updating databa ...
- 报错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 ...
- org.springframework.dao.EmptyResultDataAccessException
public Wcrash getWcrashInfo(int id) { String sql = "select plateform_id,android_version,app_ver ...
- 【异常】Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException
Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException ...
- org.springframework.dao.DataIntegrityViolationException:
数据库用的hibernate,开发工具用的myeclipse,使用开发工具连接数据库生成hibernate基于xml的po类,运行时报org.springframework.dao.DataInteg ...
- javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...
随机推荐
- js Ajax 跨域请求
一.使用jsonp的方式(只支持get请求) 二.使用cors的方式(支持HTTP的大部分请求方式) 三.apache的转发(修改服务器配置) 没有试验,暂时不详细写!
- 剑指Offer——整数中1出现的次数(从1到n整数中1出现的次数)
题目描述: 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了 ...
- System.ArgumentException: 字体“Courier New”不支持样式“Regular”。
使用MongoVUE,发现报错,报错信息如下: System.ArgumentException: 字体“Courier New”不支持样式“Regular”. 说明本机字体安装不够:需安装完整的Co ...
- 11个你应该知道的django博客引擎
这段时间一直在学python和django,准备写个小小的blog巩固下自己学到的东西,看到了GAE上的一些程序,大部分都是纯python的,想找一些基于django的,还真是难.无意中搜索到一篇文章 ...
- android推送,极光推送
android中简单易用的消息推送方式之中的一个 -------> 极光推送 首先来介绍一下极光推送. 极光推送:英文简称 JPush,是一个面向普通开发人员免费.开放的第三方消息推送服务,我们 ...
- JavaWeb-HttpServletResponse对象一
web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象,和代表响应的response对象.resquest和response对象既然代表请求和响应,那么要 ...
- JavaWeb-Servlet开发2
---恢复内容开始--- ServletConfig 配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servle ...
- 基于.net core2.1开发遇到的问题记录以及解决方案
问题1:升级EFCore 到2.1一直报'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFac ...
- dubbo总结
一 .Dubbo产生背景 单一应用架构当网站流量很小时,只需一个应用,将所有功能都部署在一起,以减少部署节点和成本.此时,用于简化增删改查工作量的 数据访问框架(ORM) 是关键. 垂直应用架构当访 ...
- python3_requests模块详解
1.模块说明 requests是使用Apache2 licensed 许可证的HTTP库. 用python编写. 比urllib2模块更简洁. Request支持HTTP连接保持和连接池,支持使用co ...