Hi,
I am trying to understand if it would be possible to use iterceptor to track and log history of entity changes.
For Example:
public class HistoryHook implements Interceptor {
private Session cs;
public HistoryHook(Session s) {
cs=s;
}
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException {
if(entity instanceof HistoryEntry) return false;
HistoryEntry h = new HistoryEntry(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types);
cs.save(h);
return false;
}
}
Can I do this?
HistoryEntry will go under same DB commit as entity?
Rihards
|