title: Entities passed to the choice field must be managed. Maybe persist them in the entity manager?
body: <p>I am new to Symfony2, and I am not getting any answer for this error message </p>
  
  <pre><code>Entities passed to the choice field must be managed. Maybe persist them in the entity manager?
  </code></pre>
  
  <p>My version of Symfony is 2.3</p>
  
  <p>I go such code in my Controller addAction()</p>
  
  <pre><code>    $em = $this-&gt;getDoctrine()-&gt;getManager();
  
      $user = new User(); //User is my main entity
      $form = $this-&gt;createFormBuilder($user)
          -&gt;add('company','entity', array(
              'class' =&gt; 'AGUserBundle:Company', //OneToMany child entity with User
              'property' =&gt; 'name',
              'multiple' =&gt; false
          ))
          -&gt;getForm();
  
      $form-&gt;add('Ajouter', 'submit', array(
          'attr' =&gt; array('class' =&gt; 'btn btn-primary'),
      ));
  
  
      $request = $this-&gt;get('request');
  
      $form-&gt;handleRequest($request);
  
      if($form-&gt;isValid()){
          $em-&gt;persist($user);
          $em-&gt;flush();
      }
  </code></pre>
  
  <p>I have an User class that have a OneToMany relationship with my Company class, everything is correctly generated by Doctrine. </p>
  
  <p>My goal is to make a user creation form with the current list of Companies, to allow user to pick one and link it to his account.</p>
  
  <p>Thanks for your help!</p>