<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Tue Jun 18 23:24:43 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-2245/DDC-2245.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-2245] EntityManager#getReference returns NULL on SINGLE_TABLE inheritance</title>
                <link>http://doctrine-project.org/jira/browse/DDC-2245</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;When EntityManager#getReference is called with SINGLE_TABLE inherited entity, it tries to get a loaded entity by calling unitOfWork-&amp;gt;tryGetById($sortedId, $class-&amp;gt;rootEntityName). The call may return an entity object of root entity class which is not what is asked, then it ends up returning NULL instead of going further.&lt;/p&gt;</description>
                <environment></environment>
            <key id="14389">DDC-2245</key>
            <summary>EntityManager#getReference returns NULL on SINGLE_TABLE inheritance</summary>
                <type id="1" iconUrl="http://doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="6">Invalid</resolution>
                                <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="mak8">Masaki Fujimoto</reporter>
                        <labels>
                    </labels>
                <created>Tue, 15 Jan 2013 21:48:20 +0000</created>
                <updated>Sun, 20 Jan 2013 17:30:28 +0000</updated>
                    <resolved>Sun, 20 Jan 2013 11:58:25 +0000</resolved>
                            <version>2.3.2</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="19331" author="ocramius" created="Tue, 15 Jan 2013 22:02:24 +0000"  >&lt;p&gt;This looks quite serious. On the other side, `getReference` should probably call `find` on inheritances.&lt;/p&gt;

&lt;p&gt;Do you have any example code for this?&lt;/p&gt;</comment>
                    <comment id="19332" author="mak8" created="Tue, 15 Jan 2013 23:24:16 +0000"  >&lt;p&gt;Yes, following line returns NULL with entity classes I have(it&apos;s a part of Symfony2 project):&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
$entity = $em-&amp;gt;getRepository(&apos;EnjoitechBaseBundle:MCode&apos;)-&amp;gt;find(&apos;01&apos;) &lt;span class=&quot;code-comment&quot;&gt;// load an entity of root entity class
&lt;/span&gt;$ref = $em-&amp;gt;getReference(&apos;Enjoitech\BaseBundle\Entity\MCodeModule&apos;, &apos;01&apos;); &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; to get reference of sub entity with same ID, &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; NULL
&lt;/span&gt;
&lt;span class=&quot;code-comment&quot;&gt;// $ref =&amp;gt; NULL
&lt;/span&gt;

&lt;span class=&quot;code-comment&quot;&gt;// MCode.php
&lt;/span&gt;&amp;lt;?php

namespace Enjoitech\BaseBundle\Entity;

use \PDO;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;M_CODE&quot;&lt;/span&gt;)
 * @ORM\InheritanceType(&lt;span class=&quot;code-quote&quot;&gt;&quot;SINGLE_TABLE&quot;&lt;/span&gt;)
 * @ORM\DiscriminatorColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;CLASS&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;, length=2)
 * @ORM\DiscriminatorMap({&lt;span class=&quot;code-quote&quot;&gt;&quot;00&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;MCode&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;01&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;MCodeModule&quot;&lt;/span&gt;})
 */
class MCode
{
    /**
     * @ORM\Id
     * @ORM\Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;, length=2)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $CODE;

    /**
     * @ORM\Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;, length=128)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $DESCRIPTION;

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getCODE()
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;CODE;
    }
}


/**
 * @ORM\Entity
 */
class MCodeModule &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; MCode
{
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I also saw a post that mentioned a similar/same issue at &lt;a href=&quot;https://groups.google.com/forum/#!msg/doctrine-user/55IkFJlADh8/79QpCIH1Ag4J&quot; class=&quot;external-link&quot;&gt;https://groups.google.com/forum/#!msg/doctrine-user/55IkFJlADh8/79QpCIH1Ag4J&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="19345" author="beberlei" created="Sun, 20 Jan 2013 11:58:25 +0000"  >&lt;p&gt;This is the correct behavior, if you fetch MCodeModule and its &quot;only&quot; a MCode, then returning null is correct, because you assume to retrieve a MCodeModule or nothing.&lt;/p&gt;</comment>
                    <comment id="19348" author="mak8" created="Sun, 20 Jan 2013 16:19:09 +0000"  >&lt;p&gt;I am not assuming getReference is supposed to fetch/retrieve/load anything. Shouldn&apos;t it return a reference to an entity object even the target entity hasn&apos;t been loaded yet? getReference won&apos;t return null because you&apos;ll never know if the entity exists in database in my opinion.&lt;/p&gt;</comment>
                    <comment id="19349" author="ocramius" created="Sun, 20 Jan 2013 16:32:03 +0000"  >&lt;p&gt;&lt;a href=&quot;http://doctrine-project.org/jira/secure/ViewProfile.jspa?name=mak8&quot; class=&quot;user-hover&quot; rel=&quot;mak8&quot;&gt;Masaki Fujimoto&lt;/a&gt; that doesn&apos;t work with inheritances, since you will need to query the discriminator column to know what object to instantiate&lt;/p&gt;</comment>
                    <comment id="19350" author="mak8" created="Sun, 20 Jan 2013 17:10:50 +0000"  >&lt;p&gt;I see, thanks for clarifying that. That was what I thought as far as I see in code; $sortedId array doesn&apos;t include discriminator column and value at all. So basically getReference won&apos;t guarantee its behaviour when the target is inheritances correct? I should rather use find() maybe. Will you keep that policy for future?&lt;/p&gt;

&lt;p&gt;I also encountered few more issues related to SINGLE_TABLE inheritance. something like find() returns entities of other inheritance class that were loaded earlier. I needed to clear entityManager each time before I get entities of another subclassed of MCode. I guess there may be same sort of implementation without considering discriminator column. Are these all known issues or it&apos;s just how it is intended?&lt;/p&gt;</comment>
                    <comment id="19351" author="ocramius" created="Sun, 20 Jan 2013 17:15:39 +0000"  >&lt;p&gt;&lt;a href=&quot;http://doctrine-project.org/jira/secure/ViewProfile.jspa?name=mak8&quot; class=&quot;user-hover&quot; rel=&quot;mak8&quot;&gt;Masaki Fujimoto&lt;/a&gt; repeated calls to `find` give you the same instances for same identifiers. If you changed something, you&apos;ll need to `clear`, though it looks like you&apos;re doing a lot of unconventional stuff in there.&lt;/p&gt;

&lt;p&gt;I think that on STI/JTI, `getReference` could short-circuit to `find`, not sure if we want it.&lt;/p&gt;</comment>
                    <comment id="19352" author="mak8" created="Sun, 20 Jan 2013 17:30:28 +0000"  >&lt;p&gt;I have just one code table. PK is a combination of CLASS and CODE columns. I use CLASS column as discriminator, and CODE column is ID of each inheritance. value in CODE column won&apos;t be unique by itself in the table but I thought SINGLE_TABLE inheritance can cover that. If this structure is unconventional, I&apos;ll have to look for workaround. thanks for all your help&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>