title: Doctrine isn't saving my entities?
body: <p>I have the following model, or as you call them entity, and I also have a controller, everything works in this action, but when I check the database there is no user. So I am curious as what I am missing. So lets start at the beginning as to what I have:</p>
  
  <p><strong><code>bootstrap.php</code></strong> contains the following code, among other things.</p>
  
  <pre><code>...
  /** ---------------------------------------------------------------- **/
  // Lets Setup Doctrine.
  /** ---------------------------------------------------------------- **/
  require_once 'vendor/autoload.php';
  
  $loader = require 'vendor/autoload.php';
  \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
  
  use Doctrine\ORM\Tools\Setup;
  use Doctrine\ORM\EntityManager;
  
  /**
   * Set up Doctrine.
   */
  class DoctrineSetup {
  
      /**
       * @var array $paths - where the entities live.
       */
      protected $paths = array(APP_MODELS);
  
      /**
       * @var bool $isDevMode - Are we considered "in development."
       */
      protected $isDevMode = false;
  
      /**
       * @var array $dbParams - The database paramters.
       */
      protected $dbParams = null;
  
      /**
       * Constructor to set some core values.
       */
      public function __construct(){
          if (!file_exists('db_config.ini')) {
              throw new \Exception(
                  'Missing db_config.ini. You can create this from the db_config_sample.ini'
              );
          }
  
          $this-&gt;dbParams = array(
              'driver' =&gt; 'pdo_mysql',
              'user' =&gt; parse_ini_file('db_config.ini')['DB_USER'],
              'password' =&gt; parse_ini_file('db_config.ini')['DB_PASSWORD'],
              'dbname' =&gt; parse_ini_file('db_config.ini')['DB_NAME']
          );
      }
  
      /**
       * Get the entity manager for use through out the app.
       *
       * @return EntityManager
       */
      public function getEntityManager() {
          $config = Setup::createAnnotationMetadataConfiguration($this-&gt;paths, $this-&gt;isDevMode, null, null, false);
          return EntityManager::create($this-&gt;dbParams, $config);
      }
  }
  
  /**
   * Function that can be called through out the app.
   *
   * @return EntityManager
   */
  function getEntityManager() {
      $ds = new DoctrineSetup();
      return $ds-&gt;getEntityManager();
  }
  
  /**
   * Function that returns the conection to the database.
   */
  function getConnection() {
      $ds = new DoctrineSetup();
      return $ds-&gt;getEntityManager()-&gt;getConnection();
  }
  ...
  </code></pre>
  
  <p>So now that we have doctrine set up its time to create a model (entity) and set which fields can and cannot be blank and so on and so forth.</p>
  
  <p><strong>Note</strong> At this point, you should know that I am not using Symfony other then its components on top of Doctrine. I am using Slim Framework. So if any suggestion is to use x or y from symfony, please make sure its a component.</p>
  
  <p><strong><code>Models/User.php</code></strong></p>
  
  <pre><code>&lt;?php
  
  namespace ImageUploader\Models;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="users", uniqueConstraints={
   *   @ORM\UniqueConstraint(name="user", columns={"userName", "email"})}
   * )
   */
  class User {
  
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue
       */
      protected $id;
  
      /**
       * @ORM\Column(type="string", length=32, nullable=false)
       * @Assert\NotBlank()
       */
      protected $firstName;
  
      /**
       * @ORM\Column(type="string", length=32, nullable=false)
       * @Assert\NotBlank()
       */
      protected $lastName;
  
      /**
       * @ORM\Column(type="string", length=100, unique=true, nullable=false)
       * @Assert\NotBlank(
       *    message = "Username cannot be blank"
       * )
       */
      protected $userName;
  
      /**
       * @ORM\Column(type="string", length=100, unique=true, nullable=false)
       * @Assert\NotBlank(
       *   message = "Email field cannot be blank."
       * )
       * @Assert\Email(
       *    message = "The email you entered is invalid.",
       *    checkMX = true
       * )
       */
      protected $email;
  
      /**
       * @ORM\Column(type="string", length=500, nullable=false)
       * @Assert\NotBlank(
       *  message = "The password field cannot be empty."
       * )
       */
      protected $password;
  
      /**
       * @ORM\Column(type="datetime", nullable=true)
       */
      protected $created_at;
  
      /**
       * @ORM\Column(type="datetime", nullable=true)
       */
      protected $updated_at;
  
      /**
       * Get the value of Created At
       *
       * @return mixed
       */
      public function getCreatedAt()
      {
          return $this-&gt;created_at;
      }
  
      /**
       * Set the value of Created At
       *
       * @param mixed created_at
       *
       * @return self
       */
      public function setCreatedAt(\DateTime $created_at = null)
      {
          $this-&gt;created_at = $created_at;
  
          return $this;
      }
  
      /**
       * Get the value of Updated At
       *
       * @return mixed
       */
      public function getUpdatedAt()
      {
          return $this-&gt;updated_at;
      }
  
      /**
       * Set the value of Updated At
       *
       * @param mixed updated_at
       *
       * @return self
       */
      public function setUpdatedAt(\DateTime $updated_at = null)
      {
          $this-&gt;updated_at = $updated_at;
  
          return $this;
      }
  
      /**
       * Get the value of First Name
       *
       * @return mixed
       */
      public function getFirstName()
      {
          return $this-&gt;firstName;
      }
  
      /**
       * Set the value of First Name
       *
       * @param mixed firstName
       *
       * @return self
       */
      public function setFirstName($firstName)
      {
          $this-&gt;firstName = $firstName;
  
          return $this;
      }
  
      /**
       * Get the value of Last Name
       *
       * @return mixed
       */
      public function getLastName()
      {
          return $this-&gt;lastName;
      }
  
      /**
       * Set the value of Last Name
       *
       * @param mixed lastName
       *
       * @return self
       */
      public function setLastName($lastName)
      {
          $this-&gt;lastName = $lastName;
  
          return $this;
      }
  
      /**
       * Get the value of User Name
       *
       * @return mixed
       */
      public function getUserName()
      {
          return $this-&gt;userName;
      }
  
      /**
       * Set the value of User Name
       *
       * @param mixed userName
       *
       * @return self
       */
      public function setUserName($userName)
      {
          $this-&gt;userName = $userName;
  
          return $this;
      }
  
      /**
       * Get the value of Email
       *
       * @return mixed
       */
      public function getEmail()
      {
          return $this-&gt;email;
      }
  
      /**
       * Set the value of Email
       *
       * @param mixed email
       *
       * @return self
       */
      public function setEmail($email)
      {
          $this-&gt;email = $email;
  
          return $this;
      }
  
      /**
       * Set ths password.
       *
       * @param string password
       *
       * @return self
       */
      public function setPassword($password) {
          $this-&gt;password = password_hash($password, PASSWORD_DEFAULT);
          return $this;
      }
  
      /**
       * Check the users password against that which is enterd.
       *
       * @param string password
       *
       * @return bool
       */
      public function checkPassword($password) {
          if (password_hash($password, PASSWORD_DEFAULT) === $this-&gt;getPassword()) {
              return true;
          }
  
          return false;
      }
  
      /**
       * Return the password value.
       *
       * @return hash
       */
      private function getPassword(){
          return $this-&gt;password;
      }
  
      /**
       * @ORM\PrePersist
       */
      public function setCreatedAtTimeStamp() {
          if (is_null($this-&gt;getCreatedAt())) {
              $this-&gt;setCreatedAt(new \DateTime());
          }
      }
  
      /**
       * @ORM\PreUpdate
       */
      public function setUpdatedAtTimeStamp() {
          if (is_null($this-&gt;getUpdatedAt())) {
              $this-&gt;setUpdatedAt(new \DateTime());
          }
      }
  }
  </code></pre>
  
  <p>The above model is correct, as far as I know, I mean when I run <code>"vendor/bin/doctrine migrations:migrate"</code> a database table <strong>is</strong> created.</p>
  
  <p>Now, where is all this used? it's used in a controller called <code>SignupController</code> under an action called <code>createAction($params)</code></p>
  
  <p><code>**createAction($params)**</code></p>
  
  <pre><code>public static function createAction($params){
    $postParams = $params-&gt;request()-&gt;post();
    $flash = new Flash();
  
    if ($postParams['password'] !== $postParams['repassword']) {
      $flash-&gt;createFlash('error', 'Your passwords do not match.');
      self::$createEncryptedPostParams($postParams);
      $params-&gt;redirect('/signup/error');
    }
  
    $user = new User();
  
    $user-&gt;setFirstName($postParams['firstname'])
         -&gt;setLastName($postParams['lastname'])
         -&gt;setUserName($postParams['username'])
         -&gt;setEmail($postParams['email'])
         -&gt;setPassword($postParams['password'])
         -&gt;setCreatedAtTimeStamp();
  
    $validator = Validator::createValidatorBuilder();
    $validator-&gt;enableAnnotationMapping();
  
    $errors = $validator-&gt;getValidator()-&gt;validate($user);
  
    if (count($errors) &gt; 0) {
        foreach($errors as $error) {
          $flash-&gt;createFlash(
              $error-&gt;getPropertyPath() . 'error',
              $error-&gt;getMessage()
          );
      }
  
      self::createEncryptedPostParams($postParams);
      $params-&gt;redirect('/signup/error');
    }
  
    $anyEncryptedErors = self::getEncryptedPostParams();
    if ($anyEncryptedErors !== null) {
      $anyEncryptedErors-&gt;destroy('error');
    }
  
    getEntityManager()-&gt;flush();
    getEntityManager()-&gt;persist($user);
  
    $flash-&gt;createFlash('success', ' You have signed up successfully! Please sign in!');
    $params-&gt;redirect('/signin');
  }
  </code></pre>
  
  <p>Now should you enter everything in correctly I show a flash of success and redirect you. <strong>THIS WORKS</strong> it redirects, it shows a flash message. But its the:</p>
  
  <pre><code>  getEntityManager()-&gt;flush();
    getEntityManager()-&gt;persist($user);
  </code></pre>
  
  <p>That I don't think is working. Why? Because doing a <code>select * from users</code> on the database in question comes back with no records.</p>
  
  <p><strong>Why?</strong></p>