DDC-2130: A problem with obtaining Entity without cache #2680

Closed
opened 2026-01-22 14:00:22 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 7, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user sergsw:

I use a custom validation constraint.
In the constraint I want to compare old and new entity, but when I take a entity from database, I got a entity witch is equvivalent the new entity.

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.

Originally created by @doctrinebot on GitHub (Nov 7, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user sergsw: I use a custom validation constraint. In the constraint I want to compare old and new entity, but when I take a entity from database, I got a entity witch is equvivalent the new entity. 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.
admin added the Bug label 2026-01-22 14:00:22 +01:00
admin closed this issue 2026-01-22 14:00:23 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2012):

Comment created by sergsw:

While I solved this problem so

I registered mine own hint.
I added folow code.

/****
     * SSW
     * @var string
     */
    const HINT*CREATE_NEW*INSTANCE = 'doctrine.create.new.instance';

And

/* 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.

@doctrinebot commented on GitHub (Nov 7, 2012): Comment created by sergsw: While I solved this problem so I registered mine own hint. I added folow code. ``` /**** * SSW * @var string */ const HINT*CREATE_NEW*INSTANCE = 'doctrine.create.new.instance'; ``` And ``` /* 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.
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2012):

Comment created by sergsw:

It's my fall.
I forgot deattach entity.

@doctrinebot commented on GitHub (Nov 7, 2012): Comment created by sergsw: It's my fall. I forgot deattach entity.
Author
Owner

@doctrinebot commented on GitHub (Nov 7, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Nov 7, 2012): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2680