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

Closed
doctrinebot opened this Issue Nov 7, 2012 · 3 comments

2 participants

@doctrinebot

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.

@doctrinebot

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

Comment created by sergsw:

It's my fall.
I forgot deattach entity.

@doctrinebot

Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment