src/ResetableEntityManager.php
public function detach($entity)
    {
        try{
            return $this->entityManager->detach($entity);
        } catch(ORMException $e) {
            if (!$this->entityManager->isOpen()) {
                $this->resetEntityManager();
            }
            throw $e;
        }
    }
public function detach($entity)
    {
        try{
            return $this->entityManager->detach($entity);
        } catch(ORMException $e) {
            if (!$this->entityManager->isOpen()) {
                $this->resetEntityManager();
            }
            throw $e;
        }
    }
Detaches an entity from the EntityManager, causing a managed entity to
become detached.  Unflushed changes made to the entity if any
(including removal of the entity), will not be synchronized to the database.
Entities which previously referenced the detached entity will continue to
reference it.

@param object $entity The entity to detach.

@return void

@throws ORMInvalidArgumentException