title: Doctrine 2 validation
body: <p>I have a problem with validation. In Doctrine 1 i used this:</p>
  
  <pre><code>if ($model-&gt;isValid()) {
      $model-&gt;save();
  } else {
      $errorStack = $model-&gt;getErrorStack();
      ...
  }
  </code></pre>
  
  <p>and in $errorStack i got the column name and the error message. But in Doctrine 2 I can use just it:</p>
  
  <p>Entity</p>
  
  <pre><code>/**
   * @PrePersist @PreUpdate
   */
  public function validate()
  {
      if ($this-&gt;name == null)) {
          throw new \Exception("Name can't be null"); 
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>try {
      $user = new \User();
      //$user-&gt;setName('name');
      $user-&gt;setCity('London');
      $this-&gt;_entityManager-&gt;persist($user); 
      $this-&gt;_entityManager-&gt;flush();
  } catch(Exception $e) {
      error_log($e-&gt;getMessage());
  } 
  </code></pre>
  
  <p>but I have two problems whit it:</p>
  
  <ul>
  <li>i don't know which column? </li>
  <li>i don't want to check unique manually</li>
  </ul>
  
  <p>If i skip validate() from entity the unique will be catched (from this error.log)</p>
  
  <pre><code>Unique violation: 7 ERROR:  duplicate key value violates unique constraint "person_email_uniq"
  </code></pre>
  
  <p>but for example the user save 2 records and the first is wrong, but the second valid, after the first save the EntityManager will close and I can't save the second(good) record because of "The EntityManager is closed".</p>
  
  <p>Which is the best solution for this problem?</p>