在UserRole中使用grails审计日志插件onSave

时间:2013-07-11 04:08:43

标签: grails grails-domain-class audit-logging

审计日志如何在springSecurity中的userRole这样的域类中起作用?

class SecUserSecRole implements Serializable {
      static auditable = true

      User user
      Role role

      ...

      def onSave = { map ->
      println "onSave userRole detected"
      }
}

非常感谢..

1 个答案:

答案 0 :(得分:1)

我不完全理解为什么这不起作用,但原因似乎是auditPlugin无法在类的id为复合时获取持久化属性。因此,它假设没有任何改变,它不会调用onSave。

生成的SecUserSecRole类基于'role', 'user'引入ID的复合键,auditPlugin正在尝试从hibernate PostInsertEvent中查找持久化的属性名称。在此不知道为什么但是当域使用复合键时属性将为空。

作为一种解决方法,尝试将域映射更改为

static mapping = {
   //id composite: ['role', 'user']
   role unique: 'user'
   version false
}

<击> 注意:这不是一个解决方案,可能有其他副作用,就springSecurity插件而言。

更新:我关注的是删除复合键可能会影响springSecurity的多对多关系,但根据Burt的post,似乎可以安全地删除复合键,并按照我在此处提到的那样创建它。

相关问题