title: FOSUserBundle/Symfony2: Validation Constraints not being checked against at all for the User entity
body: <p>I have validation constraints defined in my validation.yml for my User
  entity, but none of them are actually being called; it was working at
  one point but now none of the three constraints are being checked for.
  I get SQL unique constraint errors, so it's definitely not being
  handled in the code properly.</p>
  
  <p>Here's my validation.yml:</p>
  
  <pre><code>Acme\CPBundle\Entity\User:
     constraints:
          - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields: username, message: userExists }
          - FOS\UserBundle\Validator\Unique: {property: usernameCanonical, message: userExists}
          - Callback:
              methods: [isTimeZoneValid]
     properties:
          firstName:
              - MaxLength: 255
          lastName:
              - MaxLength: 255
          username:
              - NotBlank: { groups: [create_user] }
              - MinLength: { limit: 4, groups: [create_user] }
              - MaxLength: { limit: 50, groups: [create_user] }
          email:
              - NotBlank: { groups: [create_user, edit_user] }
              - MaxLength: { limit: 255, groups: [create_user, edit_user] }
              - Email:
                  message: The email "{{ value }}" is not a valid email
                  checkMX: true
          plainPassword:
              - NotBlank:  { groups: [create_user] }
              - MinLength: { limit: 6, groups: [create_user], message: "passwordMin {{ limit }}" }
          newPassword:
              - MinLength: { limit: 6, groups: [edit_user], message: "passwordMin {{ limit }}" }
          singleRole:
              - Choice: { callback: getAllowedRoles }
  </code></pre>
  
  <p>and here's my User Entity:</p>
  
  <pre><code>&lt;?php
  
  namespace Acme\CPBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  use FOS\UserBundle\Model\User as BaseUser;
  use Acme\CPBundle\Constant\SecurityConstant;
  use Symfony\Component\Validator\ExecutionContext;
  
  /**
  * Acme\CPBundle\Entity\User
  */
  class User extends BaseUser {
  
  /**
  * @var \Acme\CPBundle\Entity\Organization $organization
  */
  private $organization;
  
  /**
  * @var string $firstName
  */
  private $firstName;
  
  /**
  * @var string $lastName
  */
  private $lastName;
  
  /**
  * @var DateTime $timeZone
  */
  private $timeZone;
  
  /**
  * @var Role $singleRole
  */
  private $singleRole;
  
  /**
  * @var ArrayCollection $sessions
  */
  private $sessions;
  
  
  /**
  * @var integer $id
  */
  protected $id;
  
  public function __construct() {
      parent::__construct();
      $this-&gt;enabled = true;
      $this-&gt;sessions = new ArrayCollection();
  }
  
  public function setFirstName($firstName) {
      $this-&gt;firstName = $firstName;
  }
  
  public function getFirstName() {
      return $this-&gt;firstName;
  }
  
  public function setLastName($lastName) {
      $this-&gt;lastName = $lastName;
  }
  
  public function getLastName() {
      return $this-&gt;lastName;
  }
  
  public function setTimeZone($timeZone) {
      $this-&gt;timeZone = $timeZone;
  }
  
  public function getTimeZone() {
      return $this-&gt;timeZone;
  }
  
  public function getId() {
      return $this-&gt;id;
  }
  
  public function setOrganization(\Acme\CPBundle\Entity\Organization
      $organization) {
          $this-&gt;organization = $organization;
  }
  
  public function getOrganization() {
      return $this-&gt;organization;
  }
  
  public function setSingleRole($singleRole) {
      $this-&gt;singleRole = $singleRole;
  }
  
  public function getSingleRole() {
      return $this-&gt;singleRole;
  }
  
  public function setSessions($sessions) {
      $this-&gt;sessions = $sessions;
  }
  
  public function getSessions() {
      return $this-&gt;sessions;
  }
  
  /*
  * Form Validation Methods
  */
  public static function getAllowedRoles() {
      return array(SecurityConstant::ROLE_ADMIN,
          SecurityConstant::ROLE_ORG_ADMIN, SecurityConstant::ROLE_USER);
  }
  
  public function isTimeZoneValid(ExecutionContext $context) {
      $timeZoneIdentifiers = \DateTimeZone::listIdentifiers();
      if (!in_array($this-&gt;getTimeZone(), $timeZoneIdentifiers)) {
          $propertyPath = $context-&gt;getPropertyPath() . '.timeZone';
          $context-&gt;setPropertyPath($propertyPath);
          $context-&gt;addViolation('timeZoneInvalid', array(), null);
      }
  }
  </code></pre>
  
  <p>I've been trying to figure this out for days, but I have no slightest
  idea of what the problem may be.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks,</p>