Doctrine Projecthttp://www.doctrine-project.org/jira
This file is an XML representation of an issueen-us6.2.3626015-04-2014[DDC-2432] Entity can be initialized even if not foundhttp://www.doctrine-project.org/jira/browse/DDC-2432
Doctrine 2 - ORM<p>I have some data in loose consistency, trying to load a field from a certain entity will yield a EntityNotFoundException. Trying it again, for example if the group is reused in a set that gets iterated, will work but provide an empty/dirty Entity.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">try</span> {
echo $item-&gt;getGroup()-&gt;getName();
} <span class="code-keyword">catch</span> (\Doctrine\ORM\EntityNotFoundException $enfe) {
<span class="code-comment">// meh
</span>}
</pre>
</div></div>
<p>Thats probably because the proxies internal methods set _<em>isInitialized</em>_ to true on the first try. Without reverting it in case of the exception...</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> function __load()
{
<span class="code-keyword">if</span> (!$<span class="code-keyword">this</span>-&gt;__isInitialized__ &amp;&amp; $<span class="code-keyword">this</span>-&gt;_entityPersister) {
$<span class="code-keyword">this</span>-&gt;__isInitialized__ = <span class="code-keyword">true</span>;
<span class="code-keyword">if</span> ($<span class="code-keyword">this</span>-&gt;_entityPersister-&gt;load($<span class="code-keyword">this</span>-&gt;_identifier, $<span class="code-keyword">this</span>) === <span class="code-keyword">null</span>) {
<span class="code-keyword">throw</span> <span class="code-keyword">new</span> \Doctrine\ORM\EntityNotFoundException();
}
unset($<span class="code-keyword">this</span>-&gt;_entityPersister, $<span class="code-keyword">this</span>-&gt;_identifier);
}
}
</pre>
</div></div>
<p>Is there any reason to do that?</p>DDC-2432Entity can be initialized even if not foundBugCriticalResolvedFixedAllMarco PivettaChristoph RoenschMon, 6 May 2013 13:01:09 +0000Thu, 9 May 2013 21:38:43 +0000Thu, 9 May 2013 21:38:43 +00002.3.32.4ORM02<p>That is specifically there to disallow recursive load operations that may occur - did you already try this with latest master?</p><p>I did not exactly use an "Doctrine Proxy". A colleque of me implemented his own proxies, wich instead of loading from an entity manager, load stuff from a webservice. He simply used the template that a normal proxy provided and thats where i found this case, throw exception - return initialized. Wich i found would be valid for real proxies too.</p>
<p>Now i tried to use <a href="http://www.doctrine-project.org/blog/doctrine-2-4-beta.html" class="external-link" rel="nofollow">http://www.doctrine-project.org/blog/doctrine-2-4-beta.html</a> but the composer install just fails because common cant be resolved atm. So i downloaded and compiled all tarballs from github into our project. Now the proxy mechanism seems changed, with an _<em>initializer</em>_ closure<img class="emoticon" src="http://www.doctrine-project.org/jira/images/icons/emoticons/help_16.gif" height="16" width="16" align="absmiddle" alt="" border="0"/> instead. Our "Entities" in question won't work with that anymore...</p>
<p>I would have to construct a demo then, implementing real basic proxies with a RDBMS?</p><p><a href="http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=croensch" class="user-hover" rel="croensch">Christoph Roensch</a> did you try setting the minimum-stability flag in composer? Give it a try again with 2.4 and ping back - proxies changed a lot since 2.3</p><p>I reproduced it with the tutorial application, please have a look at the two commits i made on <a href="https://github.com/croensch/doctrine2-orm-tutorial/tree/DDC-2432" class="external-link" rel="nofollow">https://github.com/croensch/doctrine2-orm-tutorial/tree/DDC-2432</a></p><p>Proposed a fix at <a href="https://github.com/doctrine/doctrine2/pull/663" class="external-link" rel="nofollow">https://github.com/doctrine/doctrine2/pull/663</a></p>