title: Batch process in symfony2
body: <p>I create a custom console command in symfony2. This command will call the api to find fit jobs for all users. then I'll get a error like this.
  My code is like:</p>
  <pre><code> $em = $this-&gt;getContainer()-&gt;get('doctrine')-&gt;getEntityManager('default');
              $user = $em-&gt;getRepository('EnsUserBundle:User')-&gt;findAll();
                  foreach ($user as $user) 
                  {
                      .....
                      $em-&gt;flush();
                  }
              }
          }
  </code></pre>
  <p><img src="https://i.stack.imgur.com/cbYfF.jpg" alt="enter image description here" /></p>
  <p>Then I want to clear the entitymanager for each user.</p>
  <pre><code>$em = $this-&gt;getContainer()-&gt;get('doctrine')-&gt;getEntityManager('default');
                  $user = $em-&gt;getRepository('EnsUserBundle:User')-&gt;findAll();
                      foreach ($user as $user) 
                      {
                          .....
                          $em-&gt;flush();
                          $em-&gt;clear();
                      }
                  }
              }
  </code></pre>
  <p>It will lead to a error:
  <img src="https://i.stack.imgur.com/NmGWl.jpg" alt="enter image description here" />
  Then i try to use the batch process:</p>
  <pre><code>$em = $this-&gt;getContainer()-&gt;get('doctrine')-&gt;getEntityManager('default');
          $user = $em-&gt;getRepository('EnsUserBundle:User')-&gt;findAll();
          $iterableResult = $em-&gt;getRepository('EnsUserBundle:User')-&gt;findAll()-&gt;iterate();
          while (($row = $iterableResult-&gt;next()) !== false) 
          {
              foreach ($user as $user) 
              {
                  .....
                  $em-&gt;flush();
                  $em-&gt;clear();
              }
              $em-&gt;detach($row[0]);
          }
      }
  </code></pre>
  <p>But it leads to an error
  <img src="https://i.stack.imgur.com/bXpLI.jpg" alt="enter image description here" /></p>
  <p>So, do you have any good advices?
  Thank you !</p>