0
我重写了Hibernate EmptyInterceptor来捕获一些属性字段来做一些装饰。Hibernate Interceptor onSave和onLoad方法返回null
公共类MyEntityInterceptor扩展EmptyInterceptor我需要访问
字段时之前保存和读取数据时。我的onSave和onLoad方法如下。但是我的
实体字段返回null。请让我知道您的反馈,我在这里错过了什么?
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);
}