public function persistAndFlush($entity, $persistAll = false, $entityManager = null)
    {
        $entityManager = $this->getEntityManager($entityManager);

        $entityManager->persist($entity);
        $entityManager->flush($persistAll ? null : $entity);
    }