title: Symfony doctrine YAML mapping lifecycleCallbacks:prePersist
body: <p>So I am new to doctrine YAML mapping and I was unsure on something. Basically I have the following YAML file which I have stripped down for you and also the generated Entity file.</p>
  
  <p><strong>YAML:</strong></p>
  
  <pre><code># src/ACME/Base/UserBundle/Resources/config/doctrine/User.orm.yml
  ACME\UserBundle\Entity\User:
      table: fos_user
      type:  entity
      repositoryClass: ACME\UserBundle\Repository\User
      id:
          id:
              type: integer
              generator:
                  strategy: AUTO
      fields:
          firstName:
              type: string
              length: 30
              column: first_name
              nullable: false
          lastName:
              type: string
              length: 50
              column: last_name
              nullable: false
          dateJoined:
              type: datetime
              column: date_joined
              nullable: false   
  </code></pre>
  
  <p><strong>ENTITY:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace ACME\UserBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * User
   */
  class User
  {
      /**
       * @var integer
       */
      private $id;
  
      /**
       * @var string
       */
      private $firstName;
  
      /**
       * @var string
       */
      private $lastName;
  
      /**
       * @var \DateTime
       */
      private $dateJoined;
  
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set firstName
       *
       * @param string $firstName
       * @return User
       */
      public function setFirstName($firstName)
      {
          $this-&gt;firstName = $firstName;
  
          return $this;
      }
  
      /**
       * Get firstName
       *
       * @return string 
       */
      public function getFirstName()
      {
          return $this-&gt;firstName;
      }
  
      /**
       * Set lastName
       *
       * @param string $lastName
       * @return User
       */
      public function setLastName($lastName)
      {
          $this-&gt;lastName = $lastName;
  
          return $this;
      }
  
      /**
       * Get lastName
       *
       * @return string 
       */
      public function getLastName()
      {
          return $this-&gt;lastName;
      }
  
      /**
       * Set dateJoined
       *
       * @param \DateTime $dateJoined
       * @return User
       */
      public function setDateJoined($dateJoined)
      {
          $this-&gt;dateJoined = $dateJoined;
  
          return $this;
      }
  
      /**
       * Get dateJoined
       *
       * @return \DateTime 
       */
      public function getDateJoined()
      {
          return $this-&gt;dateJoined;
      }
  }
  </code></pre>
  
  <p>So my question is I can add the following so set the dateJoined before it saves: </p>
  
  <pre><code>lifecycleCallbacks:
          prePersist: [ setDateJoinedInsert ]
  </code></pre>
  
  <p>However my issue is that because I have created the column I also generate a mutator (setter) which means someone could then override the dateJoined value which I don't want to do. So is there a way not to generate a mutator automatically or do I have to then remove it from the entity file ? the issue I have is that if someone makes a change to the YAML file and re-generates the entity file the mutator will then be created again.</p>