<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 25 21:19:23 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-1775/DDC-1775.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-1775] Notify strategy listener is not attached for new entities</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1775</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;New entities with Notify strategy for changes and with GeneratedValue(strategy=&quot;AUTO&quot;) never get the onPropertyChanged listener attached to them. That happens because of the logic in the UOW::scheduleForInsert($entity) method. The last condition  in it &quot;isset($this-&amp;gt;entityIdentifiers&lt;span class=&quot;error&quot;&gt;&amp;#91;$oid&amp;#93;&lt;/span&gt;)&quot; is never true because the identifier is not set and therefore the code that attaches the PropertyChangedListener in addToIdentityMap is never run.&lt;/p&gt;</description>
                <environment></environment>
            <key id="13626">DDC-1775</key>
            <summary>Notify strategy listener is not attached for new entities</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="deatheriam">Oleg Namaka</reporter>
                        <labels>
                    </labels>
                <created>Wed, 11 Apr 2012 16:45:47 +0000</created>
                <updated>Sat, 7 Jul 2012 15:50:04 +0000</updated>
                    <resolved>Sat, 7 Jul 2012 15:50:04 +0000</resolved>
                            <version>2.2.1</version>
                                <fixVersion>2.2.3</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="17966" author="guilhermeblanco" created="Wed, 23 May 2012 03:54:14 +0000"  >&lt;p&gt;This is intentional to me. &lt;br/&gt;
According to code and documentation, PropertyChanged is supposed to operate over updates, never over inserts.&lt;/p&gt;

&lt;p&gt;I experimented changing the code to also notify about changed during new and the consequences were very drastic. Internally, propertyChanged creates entityChangesets that implies an UPDATE.&lt;/p&gt;

&lt;p&gt;Marking ticket as won&apos;t fix.&lt;/p&gt;</comment>
                    <comment id="17979" author="deatheriam" created="Thu, 24 May 2012 04:05:37 +0000"  >&lt;p&gt;In that case the Notify strategy is partially broken:&lt;br/&gt;
Category entity:&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\Category
 *
 * @ORM\Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;category&quot;&lt;/span&gt;)
 * @ORM\Entity
 */
class Category &lt;span class=&quot;code-keyword&quot;&gt;implements&lt;/span&gt; TimestampableInterface
 
    /**
     * Caption
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; string $caption
     * @ORM\Column(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;caption&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;text&quot;&lt;/span&gt;, nullable=&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $caption;
	
    /**
     * Added At
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; \DateTime $addedAt
     *
     * @ORM\Column(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;added_at&quot;&lt;/span&gt;, type=&lt;span class=&quot;code-quote&quot;&gt;&quot;datetime&quot;&lt;/span&gt;, nullable=&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $addedAt;

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setCaption($caption)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;caption != $caption)  {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_onPropertyChanged(&apos;caption&apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;caption, $caption);
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;caption = $caption;
        }
    }
	
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setAddedAt($addedAt)
    {
        $oldValue = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;addedAt;
		$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;addedAt = $addedAt;
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ((is_null($oldValue) || ($oldValue-&amp;gt;getTimestamp() != $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;addedAt-&amp;gt;getTimestamp()))) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_onPropertyChanged(&apos;addedAt&apos;, $oldValue, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;addedAt);
        }
    }

    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _onPropertyChanged($propName, $oldValue, $newValue)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_listeners) {
            /** @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; $listener \Doctrine\Common\PropertyChangedListener */
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_listeners as $listener) {
                $listener-&amp;gt;propertyChanged($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;, $propName, $oldValue, $newValue);
            }
        }
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function addPropertyChangedListener(PropertyChangedListener $listener)
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_listeners[] = $listener;
    }
	
..............	

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;OnFlush event handler:&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;..............

        foreach ($uow-&amp;gt;getScheduledEntityInsertions() as $entity) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($entity &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; TimestampableInterface) {
                $entity-&amp;gt;setUpdatedAt(&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \DateTime(&apos;now&apos;));
                $entity-&amp;gt;setAddedAt(&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \DateTime(&apos;now&apos;));
                $uow-&amp;gt;recomputeSingleEntityChangeSet($em-&amp;gt;getClassMetadata(get_class($entity)), $entity);
            }
        }
		
...............		
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;		
&lt;p&gt;Code that uses the entity:&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;        $cat = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Entity\Category();
        &lt;span class=&quot;code-comment&quot;&gt;// @todo &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; is a workaround until the http://www.doctrine-project.org/jira/browse/DDC-1775 is resolved
&lt;/span&gt;        $cat-&amp;gt;addPropertyChangedListener($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;getUnitOfWork());
        $cat-&amp;gt;setCaption(&apos;Please explain&apos;);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;persist($cat);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_em-&amp;gt;flush();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If there is no explicit call to the addPropertyChangedListener method, the caption field gets saved but the $addedAt remains null after flush. The entity does not have the attached listener so UnitOfWork does not know anything about the update that happened in the OnFlush event, and the recomputeSingleEntityChangeSet method skips entities with Notify strategy.&lt;/p&gt;</comment>
                    <comment id="18000" author="beberlei" created="Sun, 27 May 2012 11:42:45 +0000"  >&lt;p&gt;Changing computeScheduleInsertsChangeSets() would solve this, but it would also mean that the notifier gets injected more than once. &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;    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; function computeScheduleInsertsChangeSets()
    {
        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;entityInsertions as $entity) {
            $class = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;em-&amp;gt;getClassMetadata(get_class($entity));

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;computeChangeSet($class, $entity);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($entity &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; NotifyPropertyChanged) {
                $entity-&amp;gt;addPropertyChangedListener($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;);
            }
        }
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I think injecting in scheduleForInsert() is ok, but we have to look at potential problems also&lt;/p&gt;</comment>
                    <comment id="18227" author="beberlei" created="Sat, 7 Jul 2012 15:50:04 +0000"  >&lt;p&gt;Fixed&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>