title: Symfony/Doctrine: DateTime as primary key
body: <p>I am trying to make an Entity using a date as a primary key. The problem is that Symfony can't convert the DateTime I'm using into a string to introduce it in the IdentityMap. I get the following error during the persist of the entity:</p>
  
  <pre><code>Catchable Fatal Error: Object of class DateTime could not be converted to string in..
  </code></pre>
  
  <p>I'm using this code in the <strong>entity</strong>:</p>
  
  <pre><code>/**
   * @ORM\Id
   * @ORM\Column(type="datetime")
   */
  protected $date;
  </code></pre>
  
  <p>The error appears in the <strong>entity repository</strong>:</p>
  
  <pre><code>$em = $this-&gt;getEntityManager();
  $currentData = new CurrentData();
  ...
  $currentData-&gt;setDate(new \DateTime($dateStr));
  ...
  $em-&gt;persist($currentData);
  $em-&gt;flush();
  </code></pre>
  
  <p>How can I solve this problem? Thank you.</p>