`
monkey010
  • 浏览: 5131 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

deleted object would be re-saved的问题。

阅读更多
各位:

在多对多的关系中,我先修改一个关系,然后删除中间关联的数据,最后插入新的中间关联数据,此时报“deleted object would be re-saved by cascade......”的错误。

1、相关domain:
//权限表
class Purview {
       
    String purviewCode
   String purviewName

   static hasMany = [connRolePurview:ConnRolePurview]
       
}
//角色表
class Role {
       
   String  roleCode
  String  roleName
  String  roleDesc

  static hasMany = [connRolePurview:ConnRolePurview]
 
}
//权限角色关联表
class ConnRolePurview {
       
      Purview purview
    Role role
    String  operationType
 
    static belongsTo = [Purview,Role]
 
}

2、相关的controller的update操作:
class ConnRolePurviewController {
    ......
    def update = {
        def role = Role.get(params.id)
   
      Role.withTransaction{tx->
        try{
            //1.修改role.
           role.roleName = params.roleName
            role.roleDesc = params.roleDesc
            if(!role.save(flush:true)) {
                flash.message = "role's save error;"
                return redirect(action:edit,id:params.id)
            }
           sessionFactory.getCurrentSession().flush();
       
            //2.删除中间关联数据。
           def delRolePurview = ConnRolePurview.findAll("from ConnRolePurview crp where crp.role.id = "+params.id)
           if(delRolePurview)
               {
                for(objDel in delRolePurview)
                {
                    def delId = ConnRolePurview.get(objDel.id)
                    if(delId) {
                        delId.delete()
                         }
                }
               }

              //3.添加中间关联数据。        
            StringTokenizer st = new StringTokenizer(params.hidPurviews,"/")
              while (st.hasMoreTokens()) {
                StringTokenizer stPO = new StringTokenizer(st.nextToken(),"|")
                while (stPO.hasMoreTokens()) {
                    def purview = Purview.get(stPO.nextToken())
                    def connRolePurview = new ConnRolePurview()
                    connRolePurview.role = role
                    connRolePurview.purview = purview
                    connRolePurview.operationType = stPO.nextToken()
                                                 
                    }
               }
                               
                    return redirect(action:list)
                               
        }
        catch(Exception e){  
             tx.setRollbackOnly();
             flash.message = "the error for ("+e.toString()+")"
             return redirect(action:edit,id:params.id)
        }
               
        }
    }
}


报的错误如下:
[31766]StackTrace Sanitizing stacktrace:
org.springframework.dao.InvalidDataAccessApiUsageException:deleted object would be re-saved by cascade (remove deleted object from  associations): [ConnRolePurview#72];......

不知道这种情况如何处理?(就是先修改一个关系,然后删除中间数据,最后添加中间数据的情况。)

另外,不知道有没有其它的解决方法能够完成这样的需求,同时避免处理这种情况,例如:分步处理。(但是分步的话,对于界面操作会繁琐一些。)
分享到:
评论

相关推荐

    Hibernate 删除出现异常的解决方案.doc

    在使用Hibernate进行数据库操作时,有时会遇到一种异常情况,即在尝试删除一个对象时,系统抛出"deleted object would be re-saved by cascade (remove deleted object from associations)"的异常。这个异常通常发生...

    Exploring the location of object deleted by seam-carving

    Exploring the location of object deleted by seam-carving

    wechat-deleted-friends-master

    今天我们将深入探讨一个名为“wechat-deleted-friends-master”的开源项目,它专门针对这一问题提供了解决方案。 “wechat-deleted-friends-master”是一个专为检测和恢复已删除微信好友而设计的代码库。该项目的...

    2BE_DELETED_vdr-plugin-arghdirector:暂时的? 被遗弃的家? VDR插件Arghdirector-开源

    "2BE_DELETED_vdr-plugin-arghdirector:暂时的? 被遗弃的家? VDR插件Arghdirector-开源" 这个标题提到了一个名为"vdr-plugin-arghdirector"的VDR(Video Disk Recorder)插件。VDR是一种开源的数字视频录像机软件...

    Multiply deleted [E1, polymerase-, and pTP-] adenovirus vector persists despite deletion of the preterminal protein

    Multiply deleted [E1, polymerase-, and pTP-] adenovirus vector persists despite deletion of the preterminal protein RESEARCH ARTICLE Multiply deleted [E1, polymerase-, and pTP-] adenovirus vector ...

    alfresco-deleted-content-store-cleaner:Alfresco删除的Content Store Cleaner作业

    Alfresco删除的内容商店清洁程序 该加载项提供了一项工作,以删除“已删除的内容存储”中... 该插件将从已删除的内容存储库(通常位于${alfresco}/alf_data/contentstore.deleted ) ${alfresco}/alf_data/contentstore

    Dont Download, it will be deleted

    Dont Download, it will be deleted

    SQLite-Deleted-Records-Parser, 在SQLite数据库中,用于恢复已经删除项目的脚本.zip

    SQLite-Deleted-Records-Parser, 在SQLite数据库中,用于恢复已经删除项目的脚本 SQLite解析器在SQLite数据库中恢复删除条目并将输出放入TSV文件或者文本文件( R ) 中的脚本sqlparse.py的###Usagesqlparse.py -f/...

    Who Deleted Me - Unfriend Finder-crx插件

    语言:English 追踪谁在社交网络上使用谁。 看谁删除/联合您在社交网络上! 谁删除了我跟踪你的朋友列表,并在朋友缺少时通知你。 我们会告诉您是否删除了您或停用。 当你结交新朋友时,我们也会告诉你!

    应用Dephi 开发佳能照相机API

    {****************************************************************************** * * ... Gets an indexed child object of the designated object. Parameters: In: inRef - The reference...

    SQL Inserted和deleted详解

    ### SQL Inserted 和 Deleted 表详解 在 SQL Server 中,`Inserted` 和 `Deleted` 是两个特殊的表,它们主要用于触发器(Trigger)中。当执行 INSERT、UPDATE 或 DELETE 操作时,系统会自动创建这两个虚拟表,并...

    To be deleted

    此外,如果你是在网络环境中,比如云服务器上,删除操作可能会涉及到权限问题。你需要拥有足够的权限才能执行删除,否则需要联系管理员协助。在共享文件系统中,删除文件可能会影响到其他用户,所以要谨慎操作。 ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFlexControl.Invalidate and can be overriden (it is possible now to catch all object invalidation calls). - FIX: The TFlexPanel....

    Recover 4 all Pro V2.26

    They can be saved to another drive with a few mouseclicks (see Searching deleted files for step by step instructions). Recover4all?only lists folders that contain deleted files. Normal nondeleted ...

    xvideos.com-deleted-full.csv.zip

    xvideos.com-deleted-full.csv.zip

    delphi编译错误.txt

    37. **Constant object cannot be passed as var parameter** - **含义**: 无法将常量对象作为变参传递。 - **解决办法**: 使用可变对象或调整参数类型。 38. **Constant or type identifier expected** - **...

    RemoveSymantecMacFiles.command

    that would be deleted. No note is added if a file is not supposed to be removed by Symantec Uninstaller. -f Do not show files as they are removed. If -f is not specified, file names are shown as ...

    A project about to be deleted...-开源

    标题 "A project about to be deleted...-开源" 暗示了一个开源项目即将终止或面临废弃的状态。在开源软件的世界中,这样的情况并不罕见,因为项目可能会由于各种原因(如开发者资源不足、项目目标已完成或者有更优...

Global site tag (gtag.js) - Google Analytics