Code example for EmptyInterceptor

0
import org.hibernate.type.Type;
 
import com.norteksoft.product.orm.IdEntity; 
import com.norteksoft.product.util.ContextUtils; 
 
public class AuditInterceptor extends EmptyInterceptor {
	private static final long serialVersionUID = 1L;
 
	@Override 
	public boolean onSave(Object entity, Serializable id, Object[] state,
			String[] propertyNames, Type[] types) {
		if(entity instanceof IdEntity){ 
			for(int i=0; i<propertyNames.length; i++){
				if("creator".equals(propertyNames[i])){
					state[i] = ContextUtils.getLoginName();
				}else if("creatorName".equals(propertyNames[i])){
					state[i] = ContextUtils.getUserName();
				}else if("createdTime".equals(propertyNames[i])){
					state[i] = new Date();
				}