title: Doctrine2 ORM doesn't refresh objects that are altered outside of a script
body: <p>I really didn't know how to title this or search for an already posted question, so my apologies if this has been seen on here before.</p>
  
  <p>I am getting some undesired results with the following code:</p>
  
  <pre><code>// get object managers
  $fooManager = $this-&gt;getContainer()-&gt;get('foo_manager');
  $barManager = $this-&gt;getContainer()-&gt;get('bar_manager');
  
  // infinite loop
  for (;;) {
  
      // keep getting unitialized "foo" objects, or quit if none
      while (($foo = $fooManager-&gt;findUninitialized()) !== null) {
  
          // an uninitialized "foo" will need to make a "bar" object
          $bar = $barManager-&gt;create();
          $bar-&gt;setA('...');
  
          // save "bar" to database, update() WILL perform a flush()
          $barManager-&gt;update($bar);
  
          // make the association of "bar" to "foo"
          $foo-&gt;setBar($bar);
  
          // save "foo" to database, update() WILL perform a flush()
          $fooManager-&gt;update($foo);
  
      }
  
      // keep getting unprocessed "foo" objects, or quit if none
      while (($foo = $fooManager-&gt;findUnprocessed()) !== null) {
  
          // process the data from "foo" object's "bar"
          process($foo-&gt;getBar()-&gt;getB());
  
      }
  
  }
  </code></pre>
  
  <p>You can see that in the first <code>while</code> loop, <code>$bar</code> objects are being made and put into the database. Another script is picking up on these and doing things to them.</p>
  
  <p>In the second <code>while</code> loop, the <code>$foo</code> objects are trying to access their modified "bar" object (notice the <code>getB()</code> being called, we can assume that in another script being executed separately <code>setB()</code> was used to change the state of the object).</p>
  
  <p>However, in the second loop, when I call <code>getB()</code>, it is not returning the value I set with <code>setB()</code> in that other script.</p>
  
  <p>I can ensure all of the data is being properly persisted (and flushed) to the database, so when the <code>getB()</code> is called in that second loop, whatever was holding "B" was changed and is present in the database.</p>
  
  <p>One thing I've noticed is that in the log file, I am not seeing a query to pull in the data for "bar" when I call <code>$foo-&gt;getBar()</code> in the second loop (these should be lazily loaded). Also, if I <code>var_dump()</code> the value returned from <code>$foo-&gt;getBar()</code> in the second loop, it looks exactly like the associated "bar" object would look by the end of the first loop.</p>
  
  <p>I'm thinking that there is some kind of caching or something going on (since I've altered those "bar" objects earlier in the script execution, Doctrine seems like it is just re-using those rather than reloading their data from the database).</p>
  
  <p>I know what I am trying to do is probably not common.  What I am doing is using the Symfony2 console command features to write a few command-line "daemons" to help with processing some data; the "daemon" that contains this code is being run in conjunction with another "daemon" that processes those "bar" objects that get created.</p>
  
  <p>Curious as to whether there is a way to fix this to where in my second loop when I call the <code>$foo-&gt;getBar()</code> method, I am actually pulling the updated data from the database.  Any help is greatly appreciated.</p>