function fromEntity($entity, $class, $repository, $callback = null)
    {
        $meta = $repository->fromClass($class);

        //Create the proxy object and set the meta, node, and load callback
        $proxy = $this->createProxy($meta);
        $proxy->__setMeta($meta);
        $proxy->__setEntity($entity);
        $proxy->__setLoadCallback($callback);
        $proxy->__setEntity($entity);

        //Set the primary key property in the object to the node id.
        $pk = $meta->getPrimaryKey();
        $pk->setValue($proxy, $entity->getId());
        $proxy->__addHydrated($pk->getName());

        //Set the properties
        foreach ($meta->getProperties() as $property)
        {
            $name = $property->getName();

            //If the value isn't null in the DB, set the property to the correct value
            if($value = $entity->getProperty($name))
            {
                $property->setValue($proxy, $value);
                $proxy->__addHydrated($name);
            }
        }

        return $proxy;

    }