我有一个简单的HibernateInterceptor,基本上我想自动设置几个字段.这个拦截器(如下所示)扩展了EmptyInterceptor:
public class EntityAuditInterceptor extends EmptyInterceptor {
/**
* The Serial Version UUID.
*/
private static final long serialVersionUID = 4636626262147801287L;
/* (non-Javadoc)
* @see org.hibernate.EmptyInterceptor#onFlushDirty(java.lang.Object,java.io.Serializable,java.lang.Object[],java.lang.String[],org.hibernate.type.Type[])
*/
public boolean onFlushDirty(Object entity,Serializable id,Object[] currentState,Object[] prevIoUsState,String[] propertyNames,Type[] types) {
// doing stuff here
return false;
}
/* (non-Javadoc)
* @see org.hibernate.EmptyInterceptor#onSave(java.lang.Object,org.hibernate.type.Type[])
*/
public boolean onSave(Object entity,Object[] state,Type[] types) {
// doing stuff here
return false;
}
}
我使用弹簧配置文件进行布线,如下所示: