Strange Doctrine EntityNotFoundException

£可爱£侵袭症+ 提交于 2020-01-24 11:23:50

问题


I came across a strange behavior with Symfony and Doctrine issue, which actually found out that may be related to this bug.

request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\EntityNotFoundException: "Entity was not found." at /dev/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php line 177 {"exception":"[object] (Doctrine\ORM\EntityNotFoundException(code: 0)

To provide some code samples:

$nextItems = $this->itemManager->findNextItemByCatId($catId, 2, $allItems);

and then I am assigning the two returned results, as follows:

$output["next"] = $nextItems[0];
$output["following"] = $nextItems[1];

which then are actually returned via an API.

However, when -for testing purposes- I assign random values:

$output["next"] = "Test value 1";
$output["following"] = "Test value 2";

then no exception and error occurs and the response status is 200, as expected.

Any ideas here?


回答1:


I struggled with this a few hours then i found two solutions:

  1. apply doctrine workaround, at line 758 of BasicEntityPersister

change:

    return $entities ? $entities[0] : null;

to:

    return $entities ? $entities[0] : $entity;
  1. regenerate symfony bootstrap cache:

    composer run-script post-update-cmd --no-dev
    
    • for 2 i also upgraded mysql to 5.6



回答2:


Maybe could be obviously, but have you checking if your query return values? About your entity, make shure that is with no error (doctrine orm:validate-schema).
And by the way, i've so some problems with proxy directory - normaly on OS X (Doctrine 2. Auto generating proxies)



来源:https://stackoverflow.com/questions/29919275/strange-doctrine-entitynotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!