Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1436

Problems with identity map on self-referencing

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.1.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony2

      Description

      /**
       * @Orm\Entity
       * @Orm\Table(name="tt_content")
       */
      class Page
      {
      	/**
      	 * @Orm\Id
      	 * @Orm\GeneratedValue
      	 * @Orm\Column(type="integer", name="id")
      	 */
      	protected $id;
      
      	/**
      	 * @Orm\ManyToOne(targetEntity="Page", inversedBy="children")
      	 * @Orm\JoinColumn(name="pid", referencedColumnName="id")
      	 */
      	protected $parent;
      
      	/** @Orm\OneToMany(targetEntity="Page", mappedBy="parent") */
      	protected $children;
      
      	/** @Orm\Column(name="page_title") */
      	protected $title;
      }
      
      $id = 5;
      
      // step 1 
      $page = $this
      	->getEntityManager('read')
      	->createQuery('
      		SELECT p, parent
      		FROM OloloContentBundle:Page p
      			LEFT JOIN p.parent parent
      		WHERE p.id = :id
      	')
      	->setParameter('id', $id)
      	->getOneOrNullResult();
      
      // step 2
      $page = $this->getEntityManager('read')->find('OloloContentBundle:Page', $id);
      var_dump($page->getParent()->getParent()); // expected instance of Page, but got null
      

      When I added one more fetch join for parent then I got Page.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Can you test against master again? I made a fix in context of DDC-1452 that i think could solve this issue.

        Show
        Benjamin Eberlei added a comment - Can you test against master again? I made a fix in context of DDC-1452 that i think could solve this issue.
        Hide
        Konstantin added a comment -

        I will do it

        Show
        Konstantin added a comment - I will do it
        Hide
        Konstantin added a comment -

        I cann't run master branch on current env (Symfony 2.0.2).

        MappingException: The association mapping 'eventArea' misses the 'targetEntity' attribute, but targetEntity present. Can you merge fix into 2.1.x branch?

        Show
        Konstantin added a comment - I cann't run master branch on current env (Symfony 2.0.2). MappingException: The association mapping 'eventArea' misses the 'targetEntity' attribute, but targetEntity present. Can you merge fix into 2.1.x branch?
        Hide
        Benjamin Eberlei added a comment -

        I am not sure this fix is mergable in 2.1, also it is a rather complex change that i don't want to merge back to the stable branch for stability reasons.

        Let me try to reproduce this in a test and then go further from there.

        Show
        Benjamin Eberlei added a comment - I am not sure this fix is mergable in 2.1, also it is a rather complex change that i don't want to merge back to the stable branch for stability reasons. Let me try to reproduce this in a test and then go further from there.
        Hide
        Benjamin Eberlei added a comment -

        DDC-1452 is indeed the same bug as this one and the fix works.

        Show
        Benjamin Eberlei added a comment - DDC-1452 is indeed the same bug as this one and the fix works.
        Hide
        Benjamin Eberlei added a comment -

        I cant merge this as with the latest refactorings it gives hundrets of conflicts, but will re-apply manually.

        Show
        Benjamin Eberlei added a comment - I cant merge this as with the latest refactorings it gives hundrets of conflicts, but will re-apply manually.
        Hide
        Benjamin Eberlei added a comment -

        Backported and fixed in 2.1.x

        Show
        Benjamin Eberlei added a comment - Backported and fixed in 2.1.x
        Hide
        Konstantin added a comment -

        Thank you very much, Benjamin!

        Show
        Konstantin added a comment - Thank you very much, Benjamin!

          People

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

            Dates

            • Created:
              Updated:
              Resolved: