`
zhouchaofei2010
  • 浏览: 1087997 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

hibernate删除时报identifier of an instance of xx was altered from xx to xx

 
阅读更多

 org.hibernate.HibernateException: identifier of an instance of com.gwideal.apps.xjzeg.entity.rota.NightshiftTemporary was altered from 47392c5531464d5d97a4955c8e85a92b to fe21e9b9d5754adfaa5ada7982428cc7,47392c5531464d5d97a4955c8e85a92b

 

新泾镇公务员平台街镇版接入系统

 

大致过程:

1、页面参数是id=fe21e9b9d5754adfaa5ada7982427,47392c5531464d5d55c8e85a92b

2、action 是 implements ModelDriven<T>, Preparable的

prepare方法中对实体entity 进行了hibernate的查询操作,使之和hibernate的session关联起来

@Override

protected void prepareModel() throws Exception {

....

entity =nightShiftTemporaryManager.getNightShift(temId);

....

}

 

 3、在action中调用的方法中执行了删除操作

nightShiftTemporaryManager.deleteNightShift(removeId);其中removeId是对id的截取

然后报错,debug定位到 SimpleHibernateDao<T, PK extends Serializable>中的session.delete(entity);方法

 

4、action配置的是paramsPrepareParamsStack拦截栈,该栈中拦截器顺序如下

 

<interceptor-stack name="paramsPrepareParamsStack">
                <interceptor-ref name="exception"/>
                <interceptor-ref name="alias"/>
                <interceptor-ref name="i18n"/>
                <interceptor-ref name="checkbox"/>
                <interceptor-ref name="multiselect"/>
                <interceptor-ref name="params">
                    <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
                </interceptor-ref>
                <interceptor-ref name="servletConfig"/>
                <interceptor-ref name="prepare"/>
                <interceptor-ref name="chain"/>
                <interceptor-ref name="modelDriven"/>
                <interceptor-ref name="fileUpload"/>
                <interceptor-ref name="staticParams"/>
                <interceptor-ref name="actionMappingParams"/>
                <interceptor-ref name="params">
                    <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
                </interceptor-ref>
                <interceptor-ref name="conversionError"/>
                <interceptor-ref name="validation">
                    <param name="excludeMethods">input,back,cancel,browse</param>
                </interceptor-ref>
                <interceptor-ref name="workflow">
                    <param name="excludeMethods">input,back,cancel,browse</param>
                </interceptor-ref>
            </interceptor-stack>

 其中关键拦截器:

 

params : Sets the request parameters onto the Action

prepare :If the Action implements Preparable, calls its prepare method

modelDriven:If the Action implements ModelDriven, pushes the getModel Result onto the Value Stack

actionMappingParams:这是params 参数拦截器的子类

 

解释大概原因:

该action是实现ModelDriven的,则在modelDrivenInterceptor 拦截器中,  把entity 放入了valueStatck 中的栈顶,在接下来的actionMappingParams拦截器又把id参数赋值给了valueStatck 中root对象的id属性,这里即entity 中的id属性。所以在执行action中方法的时候,entity 的id值被赋予了参数id的值fe21e9b9d5754adfaa5ada7982428cc7,47392c5531464d5d97a4955c8e85a92b,所以在调用session.delete(entity)中。hibernate检测到了持久对象entity 的id被改变,抛出了异常;

 

由关键拦截器顺序5个步骤解释具体原因:

 

 

step1、params : Sets the request parameters onto the Action

 在该拦截器中,stuts2对action中的id属性赋值fe21e9b9d5754adfaa5ada7982428cc7,47392c5531464d5d97a4955c8e85a92b

 

step2、prepare :If the Action implements Preparable, calls its prepare method

在该拦截器中,拦截器调用了action中prepare 方法,而该方法把实体entity 和hibenate的session产生了关联,使起变成了hibernate中的持久化对象

 

step3、modelDriven:If the Action implements ModelDriven, pushes the getModel Result onto the Value Stack

在该拦截器中,把action中的实体entity 放入Value Stack中,使其在接下来的参数拦截中接受参数

 

step4、actionMappingParams:这是params 参数拦截器的子类

把请求参数id,赋给entity 的id

 

step5、所以在接下来的执行action方法中,调用session.delete(entity)中。hibernate检测到了持久对象entity 的id被改变,抛出了异常

 

 

 

 

 

分享到:
评论

相关推荐

    《S32K3xx Reference Manual》和《S32K3xx Data Sheet》

    《S32K3xx Reference Manual》 NXP Semiconductors Document identifier: S32K3XXRM Reference Manual Rev. 3, 10/2021 《S32K3xx Data Sheet》 Rev. 3 — 10/2021 Data Sheet: Technical Data

    Hibernate Reference Documentation3.1

    Table of Contents Preface 1. Introduction to Hibernate 1.1. Preface 1.2. Part 1 - The first Hibernate Application 1.2.1. The first class 1.2.2. The mapping file 1.2.3. Hibernate configuration 1.2.4. ...

    Hibernate+中文文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合...

    hibernate.properties

    hibernate.properties # # Hibernate, Relational ...## rollback generated identifier values of deleted entities to default values #hibernate.use_identifier_rollback true ## enable bytecode reflection...

    The Digital Object Identifier initiative: metadata implications

    The Digital Object Identifier initiative: metadata implications Context/status information The purpose of this document is to generate a DOI Foundation consensus paper on metadata, as a companion ...

    HibernateAPI中文版.chm

    HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...

    hibernate3.2中文文档(chm格式)

    HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object....

    Oracle数据库表名支持的最大长度是多少

    本文介绍Oralce数据库中,表名可以使用的最大长度。这个长度也是Oracle...*Cause: An identifier with more than 30 characters was specified. *Action: Specify at most 30 characters. 从这个错误提示可以看出

    VclZip pro v3.10.1

    If you currently work with VCLZip 2.X with TBlobStreams or some other type of streams, you can either define your own TkpBlobStream for instance which inherits from TkpHugeStream, or use the ...

    Hibernate中文详细学习文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合...

    Hibernate Tutorial 03 (Object Identifier).pdf

    上web tools课时老师发的关于hibernate的教程之一。大概内容看标题就知道了。需要注意的是文档全部是英文的。英文不好的童鞋就不要下了。。。

    Hibernate 中文 html 帮助文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted ...

    最全Hibernate 参考文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted ...

    hibernate 体系结构与配置 参考文档(html)

    1. Hibernate入门 1.1. 前言 1.2. 第一部分 - 第一个Hibernate应用程序 1.2.1. 第一个class 1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第...

    eac3to V3.17

    * fixed: number of subtitles was not appended to demuxed subtitles' file name * fixed: dialnorm removal (for Nero decoder) failed with some 2.0 TrueHD files v3.16 * added undocumented "-no2ndpass" ...

    Hibernate教程

    Hibernate参考文档 目录 前言 1. 翻译说明 2. 版权声明 1. 在Tomcat中快速上手 1.1. 开始Hibernate之旅 1.2. 第一个持久化类 1.3. 映射cat 1.4. 与Cat同乐 1.5. 结语 2. Hibernate入门 2.1. 前言 2.2. 第...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...

    计算机网络第六版答案

    Wifi (802.11) In a wireless LAN, wireless users transmit/receive packets to/from an base station (i.e., wireless access point) within a radius of few tens of meters. The base station is typically ...

    servlet2.4doc

    A FilterChain is an object provided by the servlet container to the developer giving a view into the invocation chain of a filtered request for a resource. FilterConfig - interface javax.servlet....

Global site tag (gtag.js) - Google Analytics