title: Doctrine: Set primary Key
body: <p>I have a table with some fields and the first is my primary key, called <code>token</code>.</p>
  <p>I need that token isn't automatically, so, I want to set this value. For example,</p>
  <pre><code>$em = $this-&gt;getDoctrine()-&gt;getManager();
  $object-&gt;setToken(&quot;first&quot;);
  $object-&gt;setValue(&quot;123&quot;);
  $em-&gt;persist($object);
  $em-&gt;flush();
  </code></pre>
  <p>But, in my DB, always token is <code>null</code>, why?</p>
  <p>When I do flush, token value disappear.</p>
  <p>In my entity, token is declared:</p>
  <pre><code>    /**
       * @var string
       *
       * @ORM\Column(name=&quot;token&quot;, type=&quot;string&quot;, length=45, nullable=false)
       * @ORM\Id
       */
      private $token;
  
      /**
       * Set token
       *
       * @param string $token
       * @return Downloads
       */
      public function setToken($token)
      {
          $this-&gt;token = $token;
      
          return $this;
      }
  
      /**
       * Get token
       *
       * @return string 
       */
      public function getToken()
      {
          return $this-&gt;token;
      }
  </code></pre>