title: Persisting serialized object in Doctrine
body: <p>Sample model:</p>
  
  <pre><code>/** @Entity */
  class Person{
      /**
       * @Id @Column(type="integer", nullable=false)
       * @GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /** @Column  */
      protected $name;
  
      /** @Column(type="datetime") */
      protected $created_at;
  
     //setters and getters...
  
     public function __construct($std){
          $this-&gt;id = $std-&gt;id;
          $this-&gt;nome = $std-&gt;nome;
          $this-&gt;created_at = new DateTime;
     }
  }
  </code></pre>
  
  <p>I'm using json to comunicate between client/server.
  I need to get the json from the client</p>
  
  <pre><code>{ "id": 123, "name": "john" }
  </code></pre>
  
  <p>and persist, keeping the field "created_at" unchanged. Doing like this:</p>
  
  <pre><code>$p = json_decode($string);
  $person = new Person($p);
  entity_manager-&gt;merge($person);
  entity_manager-&gt;flush();
  </code></pre>
  
  <p>In this case the object is updated successfully, BUT, obviously, the "created_at" field is set with the new value from "new DateTime".
  I could get a managed entity from the DB and then just change the "name", but I don´t want the unnecessary Select..</p>
  
  <p>In a nutshell, how can I perform something like this:</p>
  
  <pre><code>UPDATE Person set name = "john" where id = 123
  </code></pre>
  
  <p>Is there an annotation to ignore a property on update?
  Is there a way to set a property as unchanged?</p>
  
  <p>EDIT</p>
  
  <p>After a couple of tests using the SqlLogger, I realized that the method merge() executes a SELECT to get the current state...
  So, my solution, for now, is to get the object myself and replace only the values I wanna update. Something like:</p>
  
  <pre><code>$std = json_decode($string);
  $p = entity_manager-&gt;find('Person', $std-&gt;id);
  $p-&gt;name = $std-&gt;name;
  entity_managet-&gt;flush();
  </code></pre>
  
  <p>This way the number of "selects" is the same, but I get to keep the original values from attributes that I don't get from json.</p>