@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;
  }