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 xxKey@74e8f4a3; nested exception is org.hibernate.HibernateException: identifier of an instance of xxentity was altered from xxKey@249e3cb2 to xxKey@74e8f4a3
一共存了三张表的数据,使用了事务,前面两张表存各存1条数据,最后一张表存两条数据。执行完成后报上面的错误。后来把最后一张表实体上的联合主键去掉不报错,但最后一张表只保存成功1条数据
太奇怪了。怀疑是事务引起,检查了是使用的
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
写了单元测试,单独插入最后一张表两条数据可以成功插入。
最后找到问题关键,是因为最后一张表的其中一条数据是从数据库里读取出来的,另外一条是新插入的。把读取的数据copy到新new的实体后问题解决。
原因分析 处于Persistent状态的实体的id, hibernate是不允许修改后双保存回去。
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错误的更多相关文章
- 报错HTTP Status 500 - HHH000142: Javassist Enhancement failed: cn.itcast.entity.Customer; nested exception is org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: cn.itcast.entity.
报错 type Exception report message HHH000142: Javassist Enhancement failed: cn.itcast.entity.Customer; ...
- 解决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 ...
- 【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 ...
- 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 ...
- 报错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.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: 的解决方案
1.错误信息 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist ...
- spring 整合hibernate注解时候,出现“Unknown entity: com.ssh.entry.Admin; nested exception is org.hibernate.MappingException: Unknown entity: com.ssh.entry.Admin”异常的问题
今天学习使用ssh框架的时候,出现一个异常,弄了好久才找到,在这记录一下,我的sb错误1.spring整合hibernate,取代*.hbm.xml配置文件 在applicationContext ...
- Exception occurred during processing request: The given object has a null identifier: com.zsn.crm.Model.SaleVisit; nested exception is org.hibernate.TransientObjectException: The given object has a nu
edit.jsp页面没有加入隐藏字段 id ,导致模型驱动封装时缺少id ,,调用update更新数据库时出错!
- org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:
详细错误堆栈信息: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" ...
随机推荐
- axios获取本地文件配置步骤
首先修改一下config文件夹下面的index.js文件里面的配置,如下: 然后 ,通过axios 请求配置的接口 <script> import axios from 'axios' e ...
- Vultr账号被锁定的几个常见原因
很多小伙伴使用都在问Vultr账号为什么又是会出现被锁定的情况,今天我们就来了解一下Vultr账号被锁定的几个常见原因. 1.Vultr主机违规使用 按照Vultr主机商的要求,我们的Vultr主机也 ...
- jq-demo-点击改变图片
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Java判断链表是否为回文链表
请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 思路:1.通过快慢指针,来遍历链表 ...
- thinkphp Widget扩展
Widget扩展一般用于页面组件的扩展.大理石平台规格 举个例子,我们在页面中实现一个分类显示的Widget,首先我们要定义一个Widget控制器层 CateWidget,如下: namespace ...
- TopCoder[TCO2016 Round 1A]:EllysTree(1000)
Problem Statement Elly has a graph with N+1 vertices, conveniently numbered from 0 to N. The gr ...
- 移动Windows开始按钮到任务栏中的任何位置
uses CommCtrl; procedure TForm1.Button1Click(Sender: TObject); var vHandle: THandle; vCount: Integer ...
- Java-javaFx库运用-自动弹跳的球
(1)定义一个名为BallPane的类,用于显示一个弹动的球: (2)定义一个名为BounceBallControl的类,用来使用鼠标动作控制弹球,当鼠标按下的时候动画暂停,当鼠标释放的时候动画恢复执 ...
- C++的new和delete
#include <iostream> using namespace std; int main(int argc, char *argv[]) { int *p = NULL; //定 ...
- Delphi 中的哈希表: THashedStringList
转自万一博客 Delphi 中的哈希表: THashedStringList unit Unit1; interface uses Windows, Messages, SysUtils, Var ...