<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 25 07:36:05 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://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-1776/DDC-1776.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.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-1776] Abstract class marked as @Entity in a single table inheritance is wrongly hydrated</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1776</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;I have the following entity hierarchy:&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
 * @InheritanceType(&lt;span class=&quot;code-quote&quot;&gt;&quot;SINGLE_TABLE&quot;&lt;/span&gt;)
 * @DiscriminatorColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;type&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;)
 * @DiscriminatorMap({
     &lt;span class=&quot;code-quote&quot;&gt;&quot;prospectEdited&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;Application\Domain\Model\Event\ProspectEditedEvent&quot;&lt;/span&gt;
   })
 */
&lt;span class=&quot;code-keyword&quot;&gt;abstract&lt;/span&gt; class Event {
	&lt;span class=&quot;code-comment&quot;&gt;// ...
&lt;/span&gt;}

/**
 * @Entity
 */
&lt;span class=&quot;code-keyword&quot;&gt;abstract&lt;/span&gt; class ProspectEvent &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Event {
    /**
     * @ManyToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Application\Domain\Model\Prospect&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $prospect;
}

/**
 * @Entity
 */
class ProspectEditedEvent &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; ProspectEvent {
	&lt;span class=&quot;code-comment&quot;&gt;// ...
&lt;/span&gt;}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Although ProspectEvent is an abstract class, I need to mark it as @Entity, so that I can query for any type of ProspectEvent:&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;
SELECT e FROM ProspectEvent e WHERE e.prospect = ?
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So far, so good.&lt;br/&gt;
The problem happens when I query the root class:&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;
SELECT e FROM Event e
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The query works fine, but the returned ProspectEvent entities have a NULL $prospect property.&lt;br/&gt;
I noticed that in that case, the DocBlock for $prospect is totally ignored (a wrong @JoinColumn name for example, doesn&apos;t throw an exception).&lt;/p&gt;

&lt;p&gt;The workaround to make it work, is to add a &quot;fake&quot; entry to the discriminator map for the abstract class:&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;
@DiscriminatorMap({
  &lt;span class=&quot;code-quote&quot;&gt;&quot;prospectEvent&quot;&lt;/span&gt;  = &lt;span class=&quot;code-quote&quot;&gt;&quot;Application\Domain\Model\Event\ProspectEvent&quot;&lt;/span&gt;
  &lt;span class=&quot;code-quote&quot;&gt;&quot;prospectEdited&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;Application\Domain\Model\Event\ProspectEditedEvent&quot;&lt;/span&gt;
})
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Even though there is no such &quot;prospectEvent&quot; discriminator entry possible, as the class is abstract.&lt;br/&gt;
Final point, if I remove the @Entity DocBlock on ProspectEvent, $prospect is hydrated correctly, but then it is not possible to issue a DQL query on ProspectEvent anymore.&lt;/p&gt;</description>
                <environment>Irrelevant</environment>
            <key id="13630">DDC-1776</key>
            <summary>Abstract class marked as @Entity in a single table inheritance is wrongly hydrated</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="ocramius">Marco Pivetta</assignee>
                                <reporter username="benjamin">Benjamin Morel</reporter>
                        <labels>
                    </labels>
                <created>Sat, 14 Apr 2012 17:18:23 +0000</created>
                <updated>Wed, 1 May 2013 13:11:49 +0000</updated>
                    <resolved>Wed, 1 May 2013 13:11:49 +0000</resolved>
                            <version>2.2.2</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="19077" author="benjamin" created="Thu, 29 Nov 2012 11:58:37 +0000"  >&lt;p&gt;Any feedback?&lt;/p&gt;</comment>
                    <comment id="19388" author="ocramius" created="Wed, 23 Jan 2013 22:44:26 +0000"  >&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=benjamin&quot; class=&quot;user-hover&quot; rel=&quot;benjamin&quot;&gt;Benjamin Morel&lt;/a&gt; I&apos;d say this has to be fixed in validation. What if we enforce the fake discriminator map? The &quot;workaround&quot; you suggested is actually what you should write with correct mappings.&lt;/p&gt;</comment>
                    <comment id="19512" author="ocramius" created="Sat, 9 Feb 2013 23:56:48 +0000"  >&lt;p&gt;Yes, this has to be reported in validation somehow. The &quot;workaround&quot; is not actually a workaround, but what is expected to be written by the developer.&lt;/p&gt;</comment>
                    <comment id="19516" author="benjamin" created="Sun, 10 Feb 2013 00:12:32 +0000"  >&lt;p&gt;Ok, I found this weird because it&apos;s impossible to store a &lt;tt&gt;ProspectEvent&lt;/tt&gt; in the database (as it&apos;s &lt;tt&gt;abstract&lt;/tt&gt;), so adding a discriminator entry for it looks weird to me.&lt;br/&gt;
I would then suggest one of these two approaches:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Either remove the requirement to have a discriminator entry for the parent class if it&apos;s &lt;tt&gt;abstract&lt;/tt&gt; (this would be my preference).&lt;/li&gt;
	&lt;li&gt;Or, document this behavior, &lt;b&gt;and&lt;/b&gt; throw a proper exception if we try to persist / query such a hierarchy of classes.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;But leaving the error unreported, and instantiating incomplete objects, is a real danger!&lt;/p&gt;</comment>
                    <comment id="20159" author="beberlei" created="Wed, 1 May 2013 13:11:49 +0000"  >&lt;p&gt;We fixed errors of this kind a while ago&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>