code: public <T> Key<T> getKey(final T entity) {
          T unwrapped = entity;
          if (unwrapped instanceof ProxiedEntityReference) {
              final ProxiedEntityReference proxy = (ProxiedEntityReference) unwrapped;
              return (Key<T>) proxy.__getKey();
          }
  
          unwrapped = ProxyHelper.unwrap(unwrapped);
          if (unwrapped instanceof Key) {
              return (Key<T>) unwrapped;
          }
  
          final Object id = getId(unwrapped);
          final Class<T> aClass = (Class<T>) unwrapped.getClass();
          return id == null ? null : new Key<T>(aClass, getCollectionName(aClass), id);
      }
docs: Gets the Key for an entity
  
  @param entity the entity to process
  @param <T>    the type of the entity
  @return the Key