奇怪的Doctrine EntityNotFoundException [英] Strange Doctrine EntityNotFoundException
问题描述
我遇到了Symfony和Doctrine问题的一个奇怪的行为,实际上发现可能与这个错误。
request.CRITICAL:未捕获PHP异常
Doctrine\ORM\EntityNotFoundException:未找到实体。在
/dev/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php行
177 {exception:[object]
(Doctrine\ORM\\ \\ EntityNotFoundException(code:0)
提供一些代码示例:
$ nextItems = $ this-> itemManager-> findNextItemByCatId($ catId,2,$ allItems);
然后我分配两个返回的结果,如下所示:
$输出[next] = $ nextItems [0];
$ output [following] = $ nextItems [1];
然后实际上通过API返回。
但是,为了测试目的,我分配了随机值:
$ output [next] =测试值1;
$ output [following] =测试值2;
然后没有异常和错误发生,响应状态为200,如预期。 p>
任何想法在这里?
我在这几个小时之内遇到困难,我找到了两个解决方案:
- 应用原则解决方法,在758行的BasicEntityPersister
更改:
返回$实体? $ entities [0]:null;
to:
code> return $ entities? $ entities [0]:$ entity;
重新生成symfony bootstrap缓存: / p>
composer run-script post-update-cmd --no-dev
pre>
- 为2我还将mysql升级到5.6
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?
解决方案I struggled with this a few hours then i found two solutions:
- apply doctrine workaround, at line 758 of BasicEntityPersister
change:
return $entities ? $entities[0] : null;
to:
return $entities ? $entities[0] : $entity;
regenerate symfony bootstrap cache:
composer run-script post-update-cmd --no-dev
- for 2 i also upgraded mysql to 5.6
这篇关于奇怪的Doctrine EntityNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!