protected function setPersistence(Metadata\EntityMetadata $metadata, array $mapping)
    {
        $persisterKey = isset($mapping['key']) ? $mapping['key'] : null;
        $factory = $this->getPersistenceMetadataFactory($persisterKey);

        $persistence = $factory->createInstance($mapping);

        $metadata->setPersistence($persistence);
        return $metadata;
    }