public function getEntityMetadata($entity)
    {
        if (!$this->isManagedByDoctrine($entity)) {
            return null;
        }

        $cacheKey = 'metadata';
        $entity   = $this->getEntityClassFull($entity);
        $metadata = $this->getFromCache($entity, $cacheKey);

        if (false !== $metadata) {
            return $metadata;
        }

        $metadata = $this->entityManager->getClassMetadata($entity);
        $this->cache[$metadata->getName()][$cacheKey] = $metadata;

        return $metadata;
    }