title: Symfony2 UniqueConstraint and UniqueEntity (Integrity Violation)
body: <p>I've got a little problem with a Doctrine entity for a few days now. I've defined it with a UniqueConstraint on two fields with a UniqueEntity Validation on these two fields after that. But after validating of my form with a adding of an entity already in base, no way to obtain my error message in my form.</p>
  
  <p>Just an error message from Symfony : </p>
  
  <blockquote>
    <p>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '339057986-00012' for key 'SIRET'</p>
  </blockquote>
  
  <p>Here is my entity declaration, all seems fine to me but maybe have I forgotten or misunderstood something?</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace Proetco\FrontBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * Proetco\FrontBundle\Entity\Entreprise
   *
   * @ORM\Table(name="entreprise", uniqueConstraints={@ORM\UniqueConstraint(name="SIRET", columns={"SIREN", "NIC"})}) 
   * @ORM\Entity(repositoryClass="Proetco\FrontBundle\Entity\EntrepriseRepository")
   * @UniqueEntity(fields={"SIREN","NIC"}, message="Cette entreprise est déjà enregistrée")
   */
  class Entreprise {
  
  protected $Siret;
  
  /**
   * @var integer $id
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string $SIREN
   *
   * @ORM\Column(name="SIREN", type="string", length=9)
   */
  private $SIREN;
  
  /**
   * @var string $NIC
   *
   * @ORM\Column(name="NIC", type="string", length=5)
   */
  private $NIC;
  
  /**
   * @var string $RS
   *
   * @ORM\Column(name="RS", type="string", length=45, nullable=true)
   */
  private $RS;
  
  /**
   * @var string $NCOM
   *
   * @ORM\Column(name="NCOM", type="string", length=45, nullable=true)
   */
  private $NCOM;
  
  /**
   * @var string $CPOS
   *
   * @ORM\Column(name="CPOS", type="string", length=5, nullable=true)
   */
  private $CPOS;
  
  /**
   * @var string $LCOM
   *
   * @ORM\Column(name="LCOM", type="string", length=45, nullable=true)
   */
  private $LCOM;
  
  /**
   * @var string $INSEE
   *
   * @ORM\Column(name="INSEE", type="string", length=5, nullable=true, nullable=true)
   */
  private $INSEE;
  
  /**
   * @var string $DEP
   *
   * @ORM\Column(name="DEP", type="string", length=2)
   */
  private $DEP;
  
  /**
   * @var string $ARR
   *
   * @ORM\Column(name="ARR", type="string", length=1, nullable=true)
   */
  private $ARR;
  
  /**
   * @var string $CAN
   *
   * @ORM\Column(name="CAN", type="string", length=2, nullable=true)
   */
  private $CAN;
  
  public function getSiret()
  {
      return $this-&gt;Siret;
  }
  
  public function setSiret($Siret)
  {
      $this-&gt;Siret = $Siret;
  }
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set SIREN
   *
   * @param string $sIREN
   */
  public function setSIREN($sIREN)
  {
      $this-&gt;SIREN = $sIREN;
  }
  
  /**
   * Get SIREN
   *
   * @return string 
   */
  public function getSIREN()
  {
      return $this-&gt;SIREN;
  }
  
  /**
   * Set NIC
   *
   * @param string $nIC
   */
  public function setNIC($nIC)
  {
      $this-&gt;NIC = $nIC;
  }
  
  /**
   * Get NIC
   *
   * @return string 
   */
  public function getNIC()
  {
      return $this-&gt;NIC;
  }
  
  /**
   * Set RS
   *
   * @param string $rS
   */
  public function setRS($rS)
  {
      $this-&gt;RS = $rS;
  }
  
  /**
   * Get RS
   *
   * @return string 
   */
  public function getRS()
  {
      return $this-&gt;RS;
  }
  
  /**
   * Set NCOM
   *
   * @param string $nCOM
   */
  public function setNCOM($nCOM)
  {
      $this-&gt;NCOM = $nCOM;
  }
  
  /**
   * Get NCOM
   *
   * @return string 
   */
  public function getNCOM()
  {
      return $this-&gt;NCOM;
  }
  
  /**
   * Set CPOS
   *
   * @param string $cPOS
   */
  public function setCPOS($cPOS)
  {
      $this-&gt;CPOS = $cPOS;
  }
  
  /**
   * Get CPOS
   *
   * @return string 
   */
  public function getCPOS()
  {
      return $this-&gt;CPOS;
  }
  
  /**
   * Set LCOM
   *
   * @param string $lCOM
   */
  public function setLCOM($lCOM)
  {
      $this-&gt;LCOM = $lCOM;
  }
  
  /**
   * Get LCOM
   *
   * @return string 
   */
  public function getLCOM()
  {
      return $this-&gt;LCOM;
  }
  
  /**
   * Set INSEE
   *
   * @param string $iNSEE
   */
  public function setINSEE($iNSEE)
  {
      $this-&gt;INSEE = $iNSEE;
  }
  
  /**
   * Get INSEE
   *
   * @return string 
   */
  public function getINSEE()
  {
      return $this-&gt;INSEE;
  }
  
  /**
   * Set DEP
   *
   * @param string $dEP
   */
  public function setDEP($dEP)
  {
      if (!isset($this-&gt;DEP))
          $this-&gt;DEP = '02';
      $this-&gt;DEP = $dEP;
  }
  
  /**
   * Get DEP
   *
   * @return string 
   */
  public function getDEP()
  {
      if (!isset($this-&gt;DEP))
          $this-&gt;DEP = '02';
      return $this-&gt;DEP;
  }
  
  /**
   * Set ARR
   *
   * @param string $aRR
   */
  public function setARR($aRR)
  {
      $this-&gt;ARR = $aRR;
  }
  
  /**
   * Get ARR
   *
   * @return string 
   */
  public function getARR()
  {
      return $this-&gt;ARR;
  }
  
  /**
   * Set CAN
   *
   * @param string $cAN
   */
  public function setCAN($cAN)
  {
      $this-&gt;CAN = $cAN;
  }
  
  /**
   * Get CAN
   *
   * @return string 
   */
  public function getCAN()
  {
      return $this-&gt;CAN;
  }
  
  public function retrieveSiren($siret)
  {
      return substr($siret, 0, 9);
  }
  
  public function retrieveNic($siret)
  {
      return substr($siret, -5, 5);
  }
  
  //contraintes de validation
  //TODO : valider les champs avec Regex
  
  public function isSIREN()
  {
  
  }
  
  public function isNIC()
  {
  
  }
  
  }
  </code></pre>