title: Symfony 3.0. Notice: Undefined index: name
body: <p>I got 2 entities. Users and UserRights, mapped by ManyToOne unidirectional association. When I try to create a new user with particular userRights (created before and already existing in table) I get the error <strong>"Notice: Undefined index: name (...) in vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php at line 670"</strong>. Here are my entities:</p>
  
  <p>Users</p>
  
  <pre><code>/**
   * @ORM\Entity(repositoryClass = "AppBundle\Repository\UsersRepository")
   * @ORM\Table(name = "users")
   */
  class Users
  {
  
      /**
       * @ORM\Column(type = "string", length = 4)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy = "NONE")
       */
      protected $id;
  
      /**
       * @ORM\Column(type = "string", length = 20)
       */
      protected $name;
  
      /**
       * @ORM\Column(type = "string", length = 20)
       */
      protected $surname;
  
      /**
       * @ORM\Column(type = "string", length = 30)
       */
      protected $email;
  
      /**
       * @ORM\ManyToOne(targetEntity = "Departments")
       * @ORM\JoinColumn(name = "department", referencedColumnName = "name")
       */
      protected $department;
  
      /**
       * @ORM\Column(type = "boolean", options = {"default" = FALSE})
       */
      protected $isActive;
  
      /**
       * @ORM\ManyToOne(targetEntity = "UserRights")
       * @ORM\JoinColumn(name = "user_rights", referencedColumnName = "name")
       */
      protected $userRights;
  </code></pre>
  
  <p>UserRights:</p>
  
  <pre><code>/**
   * @ORM\Entity(repositoryClass = "AppBundle\Repository\UserRightsRepository")
   * @ORM\Table(name = "user_rights")
   */
   class UserRights
   {
       /**
        * @ORM\Column(type = "integer")
        * @ORM\Id
        * @ORM\GeneratedValue(strategy = "AUTO")
        */
       protected $id;
  
       /**
        * @ORM\Column(type = "string", length = 20, unique = TRUE)
        */
       protected $name;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>/**
  * @Route("/create/user", name="create/user")
  */
  public function createUserAction()
  {             
      $em = $this-&gt;getDoctrine()-&gt;getManager();   
      $userRights = $em-&gt;getRepository('AppBundle:UserRights')-&gt;findOneByName('Admin');   
      $department = $em-&gt;getRepository('AppBundle:Departments')-&gt;findOneByName('CN');   
  
      $user = new Users();
      $user-&gt;setId('josm');
      $user-&gt;setName('John');
      $user-&gt;setSurname('Smith');
      $user-&gt;setEmail('cos@gmail.com');
      $user-&gt;setIsActive(TRUE);
      $user-&gt;setUserRights($userRights);
      $user-&gt;setDepartment($department);
  
      $em-&gt;persist($user);
      $em-&gt;flush();
  
      return new Response(dump($user));
  }
  </code></pre>
  
  <p>When using dump($user) everything looks just fine. The problem starts when I try to put the newly created user in database with persist + flush.</p>
  
  <p>There are no errors considering syntax so I believe I do something wrong here. I assume either association or the <code>unique = true</code> is the problem here. I've read many topics and nearly all of them are all about the wrong syntax - product instead of products, customers instead of toCustomers etc. I checked my spelling a couple of times and I am quite sure it is correct.</p>