java - 拦截器 - 如何在 onCollectionUpdate 中找到上一个快照的所有者?
问题描述
所以我重写了 Hibernate Interceptor 中的 'onCollectionUpdate' 方法,以便审计实体中的集合更改。
这是我的代码:
@Override
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
if (collection != null) {
PersistentCollection persistentColl = ((PersistentCollection) collection);
Object owner = persistentColl.getOwner();
Class<?> obj = owner.getClass();
if (obj.isAnnotationPresent( AuditTrail.class )) {
Map previousStoredSnapshotMap = (Map) persistentColl.getStoredSnapshot();
Object previousCollOrMap;
if (Collection.class.isAssignableFrom( collection.getClass() )) {
previousCollOrMap = previousStoredSnapshotMap.values();
} else {
previousCollOrMap = previousStoredSnapshotMap;
}
String propertyName = persistentColl.getRole().substring( persistentColl.getRole().lastIndexOf( '.' ) + 1 );
try {
AuditTrail auditTrail = obj.getAnnotation( AuditTrail.class );
if (auditTrail.trail()) {
//logging method to be added here
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
}
}
我找到了“所有者”——父对象的当前状态。但是我怎样才能得到以前的所有者(previousStoredSnapshot 的所有者)?
谢谢
解决方案
推荐阅读
- c++ - 如何在 C++ 中克隆未知动态类型的对象?
- asp.net - 使用 PipeTransform 的 groupBy 元素的总和
- flutter - 请解释填充是如何工作的?如果我增加填充,它会变小,如果我减少填充,它会变大?但是为什么?
- regex - Linux find 命令:搜索包含括号的文件名
- java - 检查字符串在java中是否只有一个回文字符不匹配
- flutter - 在 Flutter 中关闭相机后出现白屏/黑屏
- javascript - 如何在不延迟的情况下正确获取 setInterval 内的某些元素宽度?
- python - Matlab 到 Python 的转换产生一个 SyntaxError:“不能分配给函数调用”
- cmake - cmake CheckSymbolExists 用于内在
- javascript - 我应该使用 Jquery 而不是 React 来单击切换吗?