问题描述
我有一个经过审核的模型,并且其中必须定期更新一列.Bu我不想为此栏的每次更改创建修订版本.
I have a model that is audited and there is a column in it that I have to update periodically. Bu I don't want to create revision for every change of this column.
即使更改了属性X,是否有用于不创建修订的配置?
Is there any configuration for not to create revision even if the property X's been changed?
推荐答案
要做的唯一现成的方法是实施条件审核.
The only out-of-the-box way to do what you ask is to implement Conditional Auditing.
文档中描述的条件审核方法要求用户提供自己的事件侦听器,并添加各种if检查以操纵是否审核行.
The conditional auditing approach described in the documentation requires that users provide their own event listeners and add your various if-checks to manipulate whether to audit rows or not.
我记录了一个新的概念,该概念使用类级注释来控制条件审计 HHH-11326 在这个新的JIRA中.
I have documented a new concept using class-level annotations to control conditional auditing HHH-11326 in this new JIRA.
这个想法很简单,不是让用户为事件侦听器注册而烦恼,而是可以为每个实体添加新的注释,该注释指向一个类,该类可以用作验证事件侦听器是否应执行其工作的手段还是不返回简单的true/false.
The idea is simple, that rather than have the user muck with event listener registrations, each entity could be annotated with a new annotation that points to a class which can serve as a means to verify whether that event listener should perform its job or not by simply returning true/false.
在您的特定情况下,您的听众可能看起来像这样:
In your specific case, your listener might look something like this:
public class MyEntityListener implements AuditEventListener {
public boolean doPostInsert(Object[] state) {
// we always insert the new row regardless.
return true;
}
public boolean doPostUpdate(Object[] oldState, Object[] newState) {
// checks state changes and if only toggle-changed, return false.
return !isToggleOnlyChange( oldState, newState );
}
public boolean doPreRemove(Object[] oldState) {
return true;
}
}
这个想法是,在 update 期间,如果仅更改切换字段,则返回false将影响侦听器跳过审核.
The idea is that during the update, if only the toggle field changed, returning false would influence the listener to skip the audit.
这篇关于不为特定的列更改创建修订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!