title: Doctrine 2/ Multi-step form / entity into session
body: <p>I am working under Symfony2 and Doctrine 2.1.6 and I try to setup a multi-step form.
  Between each form page, I try to send the doctrine entity into $_SESSION.</p>
  
  <p>According to that dotrine documentation it is possible and even the way to settle multipage forms:
  <a href="http://docs.doctrine-project.org/en/2.1/cookbook/entities-in-session.html" rel="nofollow">http://docs.doctrine-project.org/en/2.1/cookbook/entities-in-session.html</a></p>
  
  <p>But according to a lot of other post on stackoverflow, it is just not possible to send entities into session.</p>
  
  <p>I have the following controller Action where i pretty much copied/ past the doctrine documentation.</p>
  
  <pre><code>public function indexAction(Request $request, $id)
  {
      $session = $request-&gt;getSession();
      $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
  
      if (isset($_SESSION['propertyAdd'])) {   
      $property = $_SESSION['propertyAdd'];
      $property = $em-&gt;merge($property);
      }
  
      else {
  
      $property = new property;
  
      }
  
      $form = $this-&gt;createForm(new propertyType($this-&gt;getDoctrine()),$property);
  
      // check form
      if ($request-&gt;getMethod() == 'POST') {
              $form-&gt;bindRequest($request);
              if ($form-&gt;isValid()){
  
              $em-&gt;detach($property);
              $_SESSION['propertyAdd'] = $property;
  
              // redirection to next step here  
  
              }
              }
     return $this-&gt;render('AddProperty:'.$id.'.html.twig', array(
          'form' =&gt; $form-&gt;createView(),));
  
  }
  </code></pre>
  
  <p>the line $_SESSION['propertyAdd'] = $property; give me the following error:</p>
  
  <pre><code>Fatal error: Uncaught exception 'ErrorException' with message 'Notice: Unknown: "id" returned as member variable from __sleep() but does not exist in Unknown line 0' in G:..\Symfony\vendor\symfony\src\Symfony\Component\HttpKernel\Debug\ErrorHandler.php on line 65
  </code></pre>
  
  <p>If I replace this line by using the Symfony2 helper</p>
  
  <pre><code>$session-&gt;set('propertyAdd', $property);
  </code></pre>
  
  <p>It throws the following exception:</p>
  
  <pre><code>Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector::serialize() must return a string or NULL
  </code></pre>
  
  <p>Is the doctrine example workable.</p>