问题
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.
Is there any configuration for not to create revision even if the property X's been changed?
回答1:
The only out-of-the-box way to do what you ask is to implement Conditional Auditing.
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.
I have documented a new concept using class-level annotations to control conditional auditing HHH-11326 in this new JIRA.
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;
}
}
The idea is that during the update, if only the toggle field changed, returning false would influence the listener to skip the audit.
来源:https://stackoverflow.com/questions/17948003/not-to-create-revision-for-particular-column-change