DDC-1436: Problems with identity map on self-referencing #1801

Closed
opened 2026-01-22 13:26:23 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 18, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user koc:

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

Originally created by @doctrinebot on GitHub (Oct 18, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user koc: ``` /**** * @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.
admin added the Bug label 2026-01-22 13:26:23 +01:00
admin closed this issue 2026-01-22 13:26:24 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 14, 2011):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Nov 14, 2011): Comment created by @beberlei: Can you test against master again? I made a fix in context of [DDC-1452](http://www.doctrine-project.org/jira/browse/DDC-1452) that i think could solve this issue.
Author
Owner

@doctrinebot commented on GitHub (Nov 15, 2011):

Comment created by koc:

I will do it

@doctrinebot commented on GitHub (Nov 15, 2011): Comment created by koc: I will do it
Author
Owner

@doctrinebot commented on GitHub (Nov 15, 2011):

Comment created by koc:

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?

@doctrinebot commented on GitHub (Nov 15, 2011): Comment created by koc: 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?
Author
Owner

@doctrinebot commented on GitHub (Nov 18, 2011):

Comment created by @beberlei:

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.

@doctrinebot commented on GitHub (Nov 18, 2011): Comment created by @beberlei: 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.
Author
Owner

@doctrinebot commented on GitHub (Nov 18, 2011):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Nov 18, 2011): Comment created by @beberlei: [DDC-1452](http://www.doctrine-project.org/jira/browse/DDC-1452) is indeed the same bug as this one and the fix works.
Author
Owner

@doctrinebot commented on GitHub (Nov 18, 2011):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Nov 18, 2011): Comment created by @beberlei: I cant merge this as with the latest refactorings it gives hundrets of conflicts, but will re-apply manually.
Author
Owner

@doctrinebot commented on GitHub (Nov 18, 2011):

Comment created by @beberlei:

Backported and fixed in 2.1.x

@doctrinebot commented on GitHub (Nov 18, 2011): Comment created by @beberlei: Backported and fixed in 2.1.x
Author
Owner

@doctrinebot commented on GitHub (Nov 18, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Nov 18, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Nov 18, 2011):

Comment created by koc:

Thank you very much, Benjamin!

@doctrinebot commented on GitHub (Nov 18, 2011): Comment created by koc: Thank you very much, Benjamin!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1801