[DDC-2130] A problem with obtaining Entity without cache Created: 07/Nov/12 Updated: 07/Nov/12 Resolved: 07/Nov/12 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | ORM |
| Affects Version/s: | 2.1 |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | SergSW | Assignee: | Benjamin Eberlei |
| Resolution: | Invalid | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Symfony 2.0.18 |
||
| Attachments: |
|
| Description |
|
I use a custom validation constraint. I tried to use a query without cache
$query = $this->getDoctrine()->getRepository('SSWTestBundle:SimpleEntity')->createNamedQuery(...);
...
$query->useResultCache(FALSE);
This don't solved my problem. I tried to use a query without cache and with refresh $query = $this->getDoctrine()->getRepository('SSWTestBundle:SimpleEntity')->createNamedQuery(...); ... $query->useResultCache(FALSE); $query->setHint(\Doctrine\ORM\Query::HINT_REFRESH, true); This time I got a old entity from database, but the new entity was rollback to the old entity. In attach is my entity and TestCase. |
| Comments |
| Comment by SergSW [ 07/Nov/12 ] |
|
While I solved this problem so I registered mine own hint. DoctrineORMQuery
/**
* SSW
* @var string
*/
const HINT_CREATE_NEW_INSTANCE = 'doctrine.create.new.instance';
And DoctrineORMUnitOfWork:line 1978 /* old code if (isset($this->identityMap[$class->rootEntityName][$idHash])) { $entity = $this->identityMap[$class->rootEntityName][$idHash]; $oid = spl_object_hash($entity); ... */ if (isset($this->identityMap[$class->rootEntityName][$idHash]) && !isset($hints[Query::HINT_CREATE_NEW_INSTANCE])) { $entity = $this->identityMap[$class->rootEntityName][$idHash]; $oid = spl_object_hash($entity); if ($entity instanceof Proxy && ! $entity->__isInitialized__) { $entity->__isInitialized__ = true; ... I know it's wrong, because the new instanse overrided the old instance. |
| Comment by SergSW [ 07/Nov/12 ] |
|
It's my fall. |