问题描述
我们是否有beforeUpdateOf *(其中*是某个字段?)
以及另一个问题:
这两者都给出相同的状态。
虽然实际上object(this)的状态从x更新为y
改变了,但你可以添加一个明确的setter来执行某些操作:
class MyDomainClass {
字符串状态
void setStatus(String status){
this.status = status
//根据改变后的值做一些事情
}
}
您在 beforeUpdate
和<$ c $中看到相同的值c> afterUpdate ,因为这些回调是在Hibernate将更改后的值保存到数据库时使用的。在Hibernate启动并完成更新的时间之间改变值是不寻常的。
如果您正在从数据库中查找原始值,则可以使用它使用
do we have beforeUpdateOf* (where * is some field?)
and another question :
This both gives same status.Although actually status of object(this) is updated from x to y
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
这篇关于beforeUpdate afterUpdate之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!