Jira issue originally created by user napsi:
The find method seems to be broken. Returned objects are not managed according to the EntityManager. Fetching the same object via findAll() works.
$e = $em->find('\net\jay\products\doctrine\ProductEntityType', 1);
print "Class: " . get_class($e) . "<br>";
print "Contained: " . ($em->contains($e) === true ? 'Yes' : 'No');
This gives me:
Comment created by @beberlei:
can you try to build a reproducible test-case? This would be a serious issue, however we cannot reproduce it this way.
Comment created by napsi:
Ah it turns out to be the leading namespace \ in the find parameter that killed me. Without it, the object turns out managed.
Slightly troublesome that the object is returned in both cases perhaps.
I tested with this added to tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php, in case the behaviour needs to be changed:
public function testFind()
$user = new CmsUser;
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'developer';
$user2 = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id);
$user3 = $this->_em->find('\Doctrine\Tests\Models\CMS\CmsUser', $user->id);
Find1 passes, while Find2 fails. The user is found in both cases though.
Have a nice weekend. :)
Comment created by romanb:
That is because the objects are stored in the identity map based on their class name. We could strip off leading backslashes but once we start doing that we will always miss some places. Class names in strings are always fully-qualified, thus there is never a need to use a leading backslash in a string that contains a class name. The leading backslash is only useful in actual code, not in strings.
Maybe just mentioning it in a "common use errors" section of the manual could be a good solution to avoid too much despair when the \ is added by mistake. If it's not already mentioned in there somewhere.
Comment created by obrys:
The solution is just add a warning when leading \ is found.
The same bug happends to me. It took lots of hours to find that it was by .
Issue was closed with resolution "Fixed"