I get the following fatal error while calling find method of entityRepository in a custom entityRepository class
Fatal error: Uncaught exception 'Doctrine\ORM\OptimisticLockException' with message 'Cannot obtain optimistic lock on unversioned entity Entities\Comment' in C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\OptimisticLockException.php:62 Stack trace: #0 C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\EntityRepository.php(140): Doctrine\ORM\OptimisticLockException::notVersioned('Entities\Commen...') #1 C:\Users\user\Desktop\projects\interview\application\models\Repositories\CommentRepository.php(24): Doctrine\ORM\EntityRepository->find('Entities\Commen...', 1) #2 C:\Users\user\Desktop\projects\interview\application\controllers\CommentController.php(65): Repositories\CommentRepository->activateByIds(Array) #3 [internal function]: CommentController->approveComments() #4 C:\Users\user\Desktop\projects\interview\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #5 C:\Users\user\Desktop\projects\interview\index.php(203): require_once('C:\Users\user\D...') in C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\OptimisticLockException.php on line 62
Here is method in which i call find
public function activateByIds($arrayOfIds){
if (count($arrayOfIds)>=1) {
for ($i=0; $i<count($arrayOfIds); $i++){
$comment = parent::find('Entities\Comment', $arrayOfIds[$i]);
$comment->setIsactive(1);
$this->_em->merge($comment);
$this->_em->flush();
}
return true;
}
else return false;
}
What i'm doing wrong??