doctrine2: select error doctrine2: select error codeigniter codeigniter

doctrine2: select error


From what i read you have an OptimisticLockException

As said in this documentation:

An OptimisticLockException is thrown when a version check on an object that uses optimistic locking through a version field fails.

You can find out more about Optimistic lock here

My guess is that their is a conflict with the $comment variable:

  1. the first time you initialize $comment ($i=0) comment#1 is loaded
  2. the second time (i=1, you find comment#2 but comment is already an entity and is manged) $comment =... tries to give comment#1 the values of comment#2 even the id that is uniq, so you are creating a conflict.

try this instead :

public function activateByIds($arrayOfIds){        $comments =array();        if (count($arrayOfIds)>=1) {            foreach($arrayOfIds as $i=>$id){                $comments [$i] = $this->getEntityManager()->find('Entities\Comment', $id); //new comment, not the old one!                $comments [$i]->setIsactive(1);                $this->_em->merge($comments[$i]);                $this->_em->flush();            }            return true;        }        else return false;      unset ($comments);    }

That way you are sure that you are not trying to re-use the previous comment instead of a new one.