<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 18 16:29:27 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-1494/DDC-1494.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-1494] Query results are overwritten by previous query.</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1494</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;I am running a query that JOINs three tables, with a simple WHERE:&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;$q = $em-&amp;gt;createQuery(&quot;

SELECT cat, n, c
FROM Project_Model_NoticeCategory cat
JOIN cat.notices n
JOIN n.chapters c
WHERE
c.id = :chapter_id

&quot;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When I do this:&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;  $q-&amp;gt;setParameter(&apos;chapter_id&apos;, 1);
  $a = $q-&amp;gt;getResult();

  $q-&amp;gt;setParameter(&apos;chapter_id&apos;, 2);
  $b = $q-&amp;gt;getResult();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;$b always has the wrong results. Running the following code:&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;  $q-&amp;gt;setParameter(&apos;chapter_id&apos;, 1);
  $a = $q-&amp;gt;getResult();

  $q-&amp;gt;setParameter(&apos;chapter_id&apos;, 2);
  $b = $q-&amp;gt;getResult();
  $z = $q-&amp;gt;getArrayResult();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;BUG Results: $b != $z (getArrayResult IS CORRECT, it refreshes the results) Note: $a==$b (which is wrong)&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;There is a chapter table, this has a many-to-many join to notices (these are meta info&lt;br/&gt;
about the chapter &amp;#8211; a little like tagging a blog post) the notices are grouped into&lt;br/&gt;
categories.&lt;/p&gt;

&lt;p&gt;Data model:&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
 * @Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;chapter&quot;&lt;/span&gt;)
 */
class Project_Model_Chapter
{
    /**
     * @Id @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;integer&quot;&lt;/span&gt;)
     * @GeneratedValue(strategy=&lt;span class=&quot;code-quote&quot;&gt;&quot;AUTO&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $id;
 
    /** @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;) */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $title;

	/**
	 * @ManyToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Project_Model_Notice&quot;&lt;/span&gt;, mappedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;chapters&quot;&lt;/span&gt;)
	 */
	&lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $notices;
	
	.... /lots of code snipped/ ....
	
}


/**
 * @Entity
 * @Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;notice&quot;&lt;/span&gt;)
 */
class Project_Model_Notice
{
	/**
     * @Id @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;integer&quot;&lt;/span&gt;)
     * @GeneratedValue(strategy=&lt;span class=&quot;code-quote&quot;&gt;&quot;AUTO&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $id;
 
    /** @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;) */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $title;
	
	/**
	 * @ManyToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Project_Model_Chapter&quot;&lt;/span&gt;, inversedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;notices&quot;&lt;/span&gt;)
	 * @JoinTable(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;chapter_notice&quot;&lt;/span&gt;)
	 */
	&lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $chapters;
	
	/**
	 * @ManyToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Project_Model_NoticeCategory&quot;&lt;/span&gt;, inversedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;notices&quot;&lt;/span&gt;)
	 */
	&lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $notice_category;
	
	.... /lots of code snipped/ ....
	
}

/**
 * @Entity
 * @Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;notice_category&quot;&lt;/span&gt;)
 */
class Project_Model_NoticeCategory
{
    /**
     * @Id @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;integer&quot;&lt;/span&gt;)
     * @GeneratedValue(strategy=&lt;span class=&quot;code-quote&quot;&gt;&quot;AUTO&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $id;
	/** @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;string&quot;&lt;/span&gt;) */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $title;
	
	/**
	 * Bidirectional - One-To-Many (INVERSE SIDE)
	 *
	 * @OneToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Project_Model_Notice&quot;&lt;/span&gt;, mappedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;notice_category&quot;&lt;/span&gt;, cascade={&lt;span class=&quot;code-quote&quot;&gt;&quot;persist&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;remove&quot;&lt;/span&gt;})
	 */
	&lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $notices;

	.... /lots of code snipped/ ....
	
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Data fixtures:&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;$tools = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_NoticeCategory;
$tools-&amp;gt;setTitle(&apos;Tools&apos;);
		
$spanner = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_Notice;
$spanner-&amp;gt;setTitle(&apos;spanner&apos;);
$tools-&amp;gt;addNotice($spanner);
		
$drill = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_Notice;
$drill-&amp;gt;setTitle(&apos;power drill&apos;);
$tools-&amp;gt;addNotice($drill);
		
$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;em-&amp;gt;persist($tools);
$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;em-&amp;gt;flush();

$tools = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_NoticeCategory;
$tools-&amp;gt;setTitle(&apos;Safety&apos;);
		
$gloves = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_Notice;
$gloves-&amp;gt;setTitle(&apos;gloves&apos;);
$tools-&amp;gt;addNotice($gloves);
		
$goggles = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_Notice;
$goggles-&amp;gt;setTitle(&apos;goggles&apos;);
$tools-&amp;gt;addNotice($goggles);
		
$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;em-&amp;gt;persist($tools);
$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;em-&amp;gt;flush();

$chapter1 = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_Chapter;
$chapter1-&amp;gt;setTitle(&apos;Chapter 1&apos;);
$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;em-&amp;gt;persist($chapter1);

$chapter2 = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Project_Model_Chapter;
$chapter2-&amp;gt;setTitle(&apos;Chapter 2&apos;);
$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;em-&amp;gt;persist($chapter2);

$chapter1-&amp;gt;addNotice($spanner);
$chapter1-&amp;gt;addNotice($gloves);

$chapter2-&amp;gt;addNotice($spanner);
$chapter2-&amp;gt;addNotice($gloves);
$chapter2-&amp;gt;addNotice($drill);
$chapter2-&amp;gt;addNotice($goggles);

&lt;span class=&quot;code-comment&quot;&gt;// now persist and flush everything&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Initial investigation:&lt;/p&gt;

&lt;p&gt;I think it has something to do with HINT_REFRESH ? Stepping through:&lt;/p&gt;

&lt;p&gt;ObjectHydrator-&amp;gt;_hydrateRow&lt;br/&gt;
ObjectHydrator-&amp;gt;_getEntity&lt;/p&gt;

&lt;p&gt;when it requests the Project_Model_Category from the unit of work, it&lt;br/&gt;
seems that the second query is simply grabbing the cached results from&lt;br/&gt;
the first results. This MUST be wrong as the second query uses a&lt;br/&gt;
different query (the ID changes) and all the results are wrong.&lt;/p&gt;
</description>
                <environment>PHP 5.3 + MySQL 5.5</environment>
            <key id="13188">DDC-1494</key>
            <summary>Query results are overwritten by previous query.</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="10000" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/needinfo.png">Awaiting Feedback</status>
                    <resolution id="-1">Unresolved</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="monk.e.boy">J</reporter>
                        <labels>
                    </labels>
                <created>Tue, 15 Nov 2011 09:56:12 +0000</created>
                <updated>Sat, 9 Feb 2013 20:26:53 +0000</updated>
                                    <version>2.1.2</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="16834" author="beberlei" created="Tue, 15 Nov 2011 10:19:13 +0000"  >&lt;p&gt;Fixed formatting&lt;/p&gt;</comment>
                    <comment id="16870" author="beberlei" created="Fri, 18 Nov 2011 17:43:12 +0000"  >&lt;p&gt;are you using result caching?&lt;/p&gt;</comment>
                    <comment id="16898" author="monk.e.boy" created="Mon, 21 Nov 2011 14:45:09 +0000"  >&lt;p&gt;This is part of my bootstrap&lt;br/&gt;
,&lt;br/&gt;
,&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;		
$config = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Doctrine\ORM\Configuration();
		
$cache = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \Doctrine\Common\Cache\ArrayCache;
$config-&amp;gt;setMetadataCacheImpl($cache);
$config-&amp;gt;setQueryCacheImpl($cache);
		
&lt;span class=&quot;code-comment&quot;&gt;// driver: schema
&lt;/span&gt;$driver = $config-&amp;gt;newDefaultAnnotationDriver(
	APPLICATION_PATH . &apos;/models&apos;
);
$config-&amp;gt;setMetadataDriverImpl($driver);

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="16998" author="beberlei" created="Thu, 15 Dec 2011 20:49:29 +0000"  >&lt;p&gt;Cannot reproduce it with the script attached. Can you try to modify this to fail or write your own testcase?&lt;/p&gt;</comment>
                    <comment id="16999" author="beberlei" created="Thu, 15 Dec 2011 20:49:47 +0000"  >&lt;p&gt;Downgraded&lt;/p&gt;</comment>
                    <comment id="19499" author="asm89" created="Sat, 9 Feb 2013 20:26:43 +0000"  >&lt;p&gt;Please provide extra feedback.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11131" name="DDC1494Test.php" size="1591" author="beberlei" created="Thu, 15 Dec 2011 20:49:29 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>