beforeUpdate afterUpdate

谁都会走 提交于 2019-12-20 02:47:23

问题


do we have beforeUpdateOf* (where * is some field?)

and another question :

def beforeUpdate= { log.info("in beforeUpdate " +this.status) }

def afterUpdate = { log.info("in afterUpdate " +this.status) }

This both gives same status. Although actually status of object(this) is updated from x to y


回答1:


There's no event for when a property is changed, but you could add in an explicit setter that does something:

class MyDomainClass {
   String status

   void setStatus(String status) {
      this.status = status
      // do something based on changed value
   }
}

You're seeing the same value in beforeUpdate and afterUpdate because those callbacks are for when Hibernate saves the changed values to the database. It would be unusual for the value to change between the time that Hibernate starts and finishes the update.

If you're looking for the original value from the database, it's available using http://grails.org/doc/latest/ref/Domain%20Classes/getPersistentValue.html




回答2:


You may want to have a look at grails audit plugins: Audit Logging and Audit Trail



来源:https://stackoverflow.com/questions/9633932/beforeupdate-afterupdate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!