src/EntityRepositoryTrait.php
protected function persist($entity, $flush = true)
    {
        $entityManager = $this->getEntityManager();

        $this->validateEntity($entity, __METHOD__);
        $entityManager->persist($entity);

        if ($flush) {
            $entityManager->flush();
        }

        return $entity;
    }
protected function persist($entity, $flush = true)
    {
        $entityManager = $this->getEntityManager();

        $this->validateEntity($entity, __METHOD__);
        $entityManager->persist($entity);

        if ($flush) {
            $entityManager->flush();
        }

        return $entity;
    }
Tells the EntityManager to make an instance managed and persistent.

@param mixed $entity
@param bool  $flush

@return mixed
@throws \Doctrine\ORM\ORMInvalidArgumentException
@throws \Doctrine\ORM\OptimisticLockException
@throws \Xloit\Bridge\Doctrine\ORM\Exception\InvalidArgumentException