title: Symfony2 - Entity of type ...\Entity\Users is missing an assigned ID for field 'userId'
body: <p>I always get this message:</p>
  
  <blockquote>
    <p>Entity of type Reuzze\ReuzzeBundle\Entity\Users is missing an assigned
    ID for field 'userId'. The identifier generation strategy for this
    entity requires the ID field to be populated before
    EntityManager#persist() is called. If you want automatically generated
    identifiers instead you need to adjust the metadata mapping
    accordingly.</p>
  </blockquote>
  
  <p>I tried to delete:</p>
  
  <pre><code>@ORM\GeneratedValue(strategy="AUTO")
  </code></pre>
  
  <p>Or change it to: </p>
  
  <pre><code>@ORM\GeneratedValue(strategy="IDENTITY")
  @ORM\GeneratedValue(strategy="NONE")
  </code></pre>
  
  <p>I also pasted in:</p>
  
  <pre><code>id:
          userId:
              primary: true
              autoincrement: true
  </code></pre>
  
  <p>But nothing works!</p>
  
  <p>My UserController register action:</p>
  
  <pre><code>public function registerAction(Request $request)
      {
          if ($this-&gt;get('security.context')-&gt;isGranted('ROLE_USER'))
          {
              return $this-&gt;redirect($this-&gt;generateUrl('reuzze_reuzze_homepage'));
          }
  
          $user = new Users();
  
          $person = new Persons();
  
          $address = new Addresses();
  
          $region = new Regions();
  
          $role = new Roles();
  
          $address-&gt;setRegion($region);
  
          $user-&gt;setPerson($person);
          $user-&gt;setUserRating('1');
          $user-&gt;setRole($role);
  
          $person-&gt;setAddress($address);
  
          $address-&gt;setRegion($region);
  
          $role-&gt;setRoleName('Student');
  
          $form = $this-&gt;createForm(new RegisterType(), $user);
  
          if ($request-&gt;getMethod() == 'POST')
          {
              $form-&gt;bind($request);
  
              if($form-&gt;isValid())
              {
                  $factory = $this-&gt;get('security.encoder_factory');
                  $encoder = $factory-&gt;getEncoder($user);
                  $password = $encoder-&gt;encodePassword($user-&gt;getuserPassword(), $user-&gt;getuserSalt());
                  $user-&gt;setuserPassword($password);
  
                  $user-&gt;setRole($role);
  
                  $date = new \DateTime('NOW');
                  //$user-&gt;setuserId('1');
                  $user-&gt;setuserCreated($date);
  
                  $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
  
                  $entityManager-&gt;persist($user);
                  $entityManager-&gt;persist($person);
                  $entityManager-&gt;persist($address);
                  $entityManager-&gt;persist($region);
                  $entityManager-&gt;persist($role);
  
                  $entityManager-&gt;flush();
  
                  return $this-&gt;redirect($this-&gt;generateUrl('reuzze_reuzze_homepage'));
              }
          }
  
          return $this-&gt;render('ReuzzeReuzzeBundle:User:register.html.twig', array(
              'form' =&gt; $form-&gt;createView()
          ));
      }
  </code></pre>
  
  <p>My RegisterType:</p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('person'     , new PersonType())
              -&gt;add('userUsername'   , 'text', array(
                  'label' =&gt; 'Username',
                  'attr' =&gt; array('placeholder' =&gt; 'Username')
              ))
              -&gt;add('userEmail'       , 'email', array(
                  'label' =&gt; 'E-mailadres',
                  'attr' =&gt; array('placeholder' =&gt; 'E-mail address')
              ))
              -&gt;add('userSalt' , 'repeated', array(
                  'type' =&gt; 'password',
                  'first_name' =&gt; 'password',
                  'second_name' =&gt; 'confirm',
                  'first_options' =&gt; array(
                      'attr' =&gt; array('class' =&gt; 'form-control', 'placeholder' =&gt; 'Password'),
                      'label' =&gt; 'Password',
                  ),
                  'second_options' =&gt; array(
                      'label' =&gt; 'Repeat Password',
                      'attr' =&gt; array('class' =&gt; 'form-control', 'placeholder' =&gt; 'Repeat Password'),
                  ),
                  'invalid_message' =&gt; 'The passwords are not identical!',
              )
          );
      }
  </code></pre>
  
  <p>Users Model (userId)</p>
  
  <pre><code> /**
       * @var integer
       *
       * @ORM\Column(name="user_id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $userId;
  
  /**
       * Set userId
       *
       * @param integer $userId
       * @return Users
       */
      public function setUserId($userId)
      {
          $this-&gt;userId = $userId;
  
          return $this;
      }
  
      /**
       * Get userId
       *
       * @return integer 
       */
      public function getUserId()
      {
          return $this-&gt;userId;
      }
  </code></pre>
  
  <p>The only thing that works is when I put <strong>$user->setuserId('1');</strong> in the Usercontroller register action. But obviously that isn't what I want, someone has a fix?</p>
  
  <p>If I comment <strong>$entityManager->persist($user);</strong> in my UserController it creates all the other objects except for the User, but I don't get an error in this case.</p>