title: Doctrine2 FindOneBy function returns empty array
body: <p>I'm using Symfony2 along with doctrine2.</p>
  
  <p>I need to know if a <code>username</code> exist on a table, so I'm calling this method by AJAX...</p>
  
  <pre><code>public function existeUsername()
  {
      $req = $this-&gt;getRequest();
      $user = $req-&gt;request-&gt;get('user');
      $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
      $usuario = $em-&gt;getRepository('RECURSIVAUserBundle:Usuario')-&gt;findOneByUsername($user);
      if ($usuario): 
          //user found
          $response = new Response(json_encode(array('error' =&gt; true, 'usuario' =&gt; $usuario, 'user' =&gt; $user)));
          $response-&gt;headers-&gt;set('Content-Type', 'application/json');
          return $response;
      else: 
          //did not found the user
          $response = new Response(json_encode(array('error' =&gt; false, 'user' =&gt; $user)));
          $response-&gt;headers-&gt;set('Content-Type', 'application/json');
          return $response;
      endif;
  }
  </code></pre>
  
  <p>The method works as expected returning true if the <code>username</code> exists in the database or false if not. But when returning the user data from an existing user <code>($usuario)</code>, it always return an empty JSON array ({}) and not the expected object. Any ideas?</p>
  
  <p>If I <code>var_dump($usuario</code>) before returning the response it prints out all the correct fields and values for that <code>username</code>.</p>