【发布时间】:2014-06-23 20:14:21
【问题描述】:
我重写了 Hibernate EmptyInterceptor 来捕获一些属性字段来做一些装饰。
public class MyEntityInterceptor extends EmptyInterceptor我需要访问
保存前和读取时的字段。我的 onSave 和 onLoad 方法如下。但是我的
实体字段返回空值。请让我知道您的反馈以及我在这里遗漏了什么?
public boolean onLoad(Object entity,Serializable id, Object[] state,String[] propertyNames, Type[] types)
throws CallbackException{
Persistable entity = (Persistable) entity;
System.out.println("===============>"+entity.getCreatedBy());//returns null
return true;
}
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
if (entity instanceof IPersistable) {
IPersistable entity = (IPersistable) entity;
System.out.println("Created By=================>"+((IPersistable) entity).getCreatedBy());//Returns null
}
return (true);
}
【问题讨论】:
标签: hibernate