Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2130

A problem with obtaining Entity without cache

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony 2.0.18

      Description

      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.

      1. SimpleEntity.php
        1 kB
        SergSW
      2. SimpleEntityTest.php
        5 kB
        SergSW

        Activity

        Hide
        SergSW added a comment -

        It's my fall.
        I forgot deattach entity.

        Show
        SergSW added a comment - It's my fall. I forgot deattach entity.
        Hide
        SergSW added a comment -

        While I solved this problem so

        I registered mine own hint.
        I added folow code.

        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.

        Show
        SergSW added a comment - While I solved this problem so I registered mine own hint. I added folow code. 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.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            SergSW
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: