title: Doctrine: Object of class User could not be converted to string
body: <p>I keep getting this error with Doctrine:</p>
  
  <pre><code>PHP Catchable fatal error:  Object of class User could not be converted to string in vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1337
  </code></pre>
  
  <p>In my system users can have many permissions in a One to Many relationship. I have set up a <code>User</code> and <code>Permission</code> entity. They look like this (I removed some annotations, getters and setters to reduce clutter):</p>
  
  <pre><code>class User {
  
     /**
      * @ORM\Column(name="user_id", type="integer", nullable=false)
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="IDENTITY")
      */
     protected $id;
  
     public function getId()
     {
        return $this-&gt;id;
     }
  
     /**
      * @ORM\OneToMany(targetEntity="Permission", mappedBy="user", cascade={"persist"})
      */
     protected $permissions;
  
     public function getPermissions()
     {
        return $this-&gt;permissions;
     }
  
  }
  
  class Permission {
  
     /**
      * @ORM\Column(name="user_id", type="integer")
      * @ORM\ManyToOne(targetEntity="User", inversedBy="permissions")
      */
     protected $user;
  
     public function getUser()
     {
        return $this-&gt;user;
     }
  
     public function setUser( $user )
     {
        $this-&gt;user = $user;
  
        return $this;
     }
  }
  </code></pre>
  
  <p>The problem occurs when I add a new <code>Permission</code> to a <code>User</code>:</p>
  
  <pre><code>$permission = new Permission();
  
  $user-&gt;getPermissions()-&gt;add( $permission );
  
  $em-&gt;persist( $user );
  $em-&gt;flush();
  </code></pre>
  
  <p>This is the last bit of my stack trace:</p>
  
  <pre><code>PHP  11. Doctrine\ORM\UnitOfWork-&gt;persist() vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:565
  PHP  12. Doctrine\ORM\UnitOfWork-&gt;doPersist() vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1555
  PHP  13. Doctrine\ORM\UnitOfWork-&gt;cascadePersist() vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1615
  PHP  14. Doctrine\ORM\UnitOfWork-&gt;doPersist() vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:2169
  PHP  15. Doctrine\ORM\UnitOfWork-&gt;persistNew() vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1597
  PHP  16. Doctrine\ORM\UnitOfWork-&gt;scheduleForInsert() doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:836
  PHP  17. Doctrine\ORM\UnitOfWork-&gt;addToIdentityMap() vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1157
  PHP  18. implode() vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1337
  </code></pre>
  
  <p>Any insight would be greatly appreciated.</p>