public void refresh(Object proxifiedEntity, EntityOperations context)
      throws AchillesStaleObjectStateException {
    Object primaryKey = context.getPrimaryKey();
    log.debug(
        "Refreshing entity of class {} and primary key {}",
        context.getEntityClass().getCanonicalName(),
        primaryKey);

    ProxyInterceptor<Object> interceptor = proxifier.getInterceptor(proxifiedEntity);
    Object entity = context.getEntity();

    interceptor.getDirtyMap().clear();

    Object freshEntity = loader.load(context, context.getEntityClass());

    if (freshEntity == null) {
      throw new AchillesStaleObjectStateException(
          "The entity '"
              + entity
              + "' with primary_key '"
              + primaryKey
              + "' no longer exists in Cassandra");
    }
    interceptor.setTarget(freshEntity);
    interceptor.getAlreadyLoaded().clear();
    interceptor.getAlreadyLoaded().addAll(context.getAllGettersExceptCounters());
  }
  @SuppressWarnings("unchecked")
  public <T> T getRealObject(T proxy) {
    log.debug("Get real entity from proxy {} ", proxy);

    if (isProxy(proxy)) {
      Factory factory = (Factory) proxy;
      ProxyInterceptor<T> interceptor = (ProxyInterceptor<T>) factory.getCallback(0);
      return (T) interceptor.getTarget();
    } else {
      return proxy;
    }
  }
  @SuppressWarnings("unchecked")
  public <T> Class<T> deriveBaseClass(Object entity) {
    log.debug("Deriving base class for entity {} ", entity);

    Class<T> baseClass = (Class<T>) entity.getClass();
    if (isProxy(entity)) {
      ProxyInterceptor<?> interceptor = getInterceptor(entity);
      baseClass = (Class<T>) interceptor.getTarget().getClass();
    }

    return baseClass;
  }