The EntityManager is closed

前端 未结 17 1752
星月不相逢
星月不相逢 2020-11-29 18:36
[Doctrine\\ORM\\ORMException]   
The EntityManager is closed.  

After I get a DBAL exception when inserting data, EntityManager closes and I\'m not

17条回答
  •  旧巷少年郎
    2020-11-29 18:56

    I faced the same problem. After looking at several places here is how I dealt with it.

    //function in some model/utility
    function someFunction($em){
        try{
            //code which may throw exception and lead to closing of entity manager
        }
        catch(Exception $e){
            //handle exception
            return false;
        }
        return true;
    }
    
    //in controller assuming entity manager is in $this->em 
    $result = someFunction($this->em);
    if(!$result){
        $this->getDoctrine()->resetEntityManager();
        $this->em = $this->getDoctrine()->getManager();
    }
    

    Hope this helps someone!

提交回复
热议问题