title: Removing an object with em->remove($user) removes all objects in table
body: <p>I have a User entity that implements UserInterface to use with a RBAC system. I have not implemented the whole system yet. However, when I try to remove a user with the following code, the action removes all the users and other associated objects in other tables and then throws me an error. I am able to remove objects from other entities without issues.</p>
  
  <p>User entity</p>
  
  <pre><code>class User implements UserInterface
  {
   **
   * @var integer $id
   *
   * @ORM\Column(name="id", type="smallint")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   * 
  protected $id;
  
   **
   * @var string $username
   *
   * @ORM\Column(name="username", type="string", length=20, unique=TRUE)
   * 
  protected $username;
  
   **
   * @var string $password
   *
   * @ORM\Column(name="password", type="string", length=255)
   * 
  protected $password;
  
   **
   * @var string $salt
   *
   * @ORM\Column(name="salt", type="string", length=255)
   * 
  protected $salt;
  
   **
   * @var string $fullName
   *
   * @ORM\Column(name="full_name", type="string", length=60, unique=TRUE)
   * 
  protected $fullName;
  
   **
   * @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist", "remove"})
   * @ORM\JoinTable(name="users_roles")
   * 
   * @var ArrayCollection $userRoles
   * 
  protected $userRoles;
  
  public function __construct()
  {
      $this-&gt;userRoles = new ArrayCollection();
  }
  }
  </code></pre>
  
  <p>Delete action</p>
  
  <pre><code>public function deleteUserAction($id) {
  $user = $em-&gt;getRepository('ACMECompanyBundle:User')-&gt;find($id);
  $currentUser = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
  if ($id == $currentUser-&gt;getId()) {
      return new Response("You cannot delete the current user");
  }        
  if (!$user) {
      throw $this-&gt;createNotFoundException('No user found for id '.$id);
  }
  try {
      $em-&gt;remove($user);
      $em-&gt;flush();
      $msg = "User deleted!";
      $code = "OK";
  } catch (DBALException $e) {
      return new Response($e);
      $msg = "User cannot be deleted!";
      $code = "ERR";
  }
  $response = new Response(json_encode(array('code' =&gt; $code, 'msg' =&gt; $msg)));
  $response-&gt;headers-&gt;set('Content-Type', 'application/json');
  return $response;
  }
  </code></pre>
  
  <p>The error returned after all users are removed is </p>
  
  <blockquote>
    <p>InvalidArgumentException: You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.</p>
  </blockquote>