title: Symfony2 Form why my form return warning: json_encode(): recursion detected?
body: <p>I have to entities, Applications and Votes.</p>
  
  <p>The idea is to relate many to one. So Applications have many Votes and one Vote is for one Application.</p>
  
  <p>In my entities class I have settings like this:</p>
  
  <p>Application Entity Class:</p>
  
  <pre><code>\/**
  \* @ORM\OneToMany(targetEntity="Vote", mappedBy="application")
  \*/
  \private $votes;
  </code></pre>
  
  <p>Vote  Entity Class:</p>
  
  <pre><code>\/**
  \* @ORM\ManyToOne(targetEntity="Application", inversedBy="votes")
  \* @ORM\JoinColumn(referencedColumnName="id")
  \*/
  \private $application;
  </code></pre>
  
  <p>I think this relation is set up well or am I mistaken ?</p>
  
  <p>Next thing is that I have a form builder class for only one field:</p>
  
  <pre><code>$builder-&gt;add('rate')
      -&gt;add('save', 'submit');
  </code></pre>
  
  <p>The Votes entity has fields: <code>(id, username, rate, createdAt, updatedAt, application)</code></p>
  
  <p>and in my controller I'm doing something like this:</p>
  
  <pre><code>    $vote = new Vote();
      $form = $this-&gt;createForm(new VoteType(), $vote);
  
      $form-&gt;handleRequest($this-&gt;getRequest());
  
      if ($form-&gt;isValid()) {
          $vote-&gt;setUserName($tenant-&gt;getUsername());
          $vote-&gt;setApplication($app);
          $em-&gt;persist($vote);
          $em-&gt;flush();
  
          $this-&gt;get('session')-&gt;getFlashBag()-&gt;add('success', 'Oceniono aplikację.');
  
          return $this-&gt;redirect($this-&gt;generateUrl('applications_main'));
      }
  
      return array( 'form' =&gt; $form-&gt;createView(), );
  </code></pre>
  
  <p>and it isn't working, it returns me error:</p>
  
  <pre><code>ContextErrorException: Warning: json_encode(): recursion detected in E:\wamp\www\project\vendor\symfony\symfony\src\Symfony\Component\HttpFoundation\JsonResponse.php line 92
  </code></pre>
  
  <p>stack trace (plain text): <a href="http://pastebin.com/bSQTDJQY" rel="nofollow">http://pastebin.com/bSQTDJQY</a></p>