Check if entity was already persisted to EntityManager in Symfony2

doctrine, entitymanager, symfony

Solution

yes you shoud use the unitOfWork http://phpdox.de/demo/Symfony2/classes/Doctrine_ORM_UnitOfWork.xhtml#isEntityScheduled

$uow = $this->getDoctrine()->getManager()->getUnitOfWork()
$exist =  $uow->isEntityScheduled(  $entity );

Problem

In Symfony2, is it possible to check if particular entity was already persisted and is present in the EntityManager? I'm working with some data import and some of the records might be exact duplicates. I'm doing bulk inserts, i.e., calling flush() only after certain amount of entities were persisted. So, I need to check if the entity I am trying to persist is not in the EntityManager already.

Original source