title: UniqueEntity using Doctrine 2
body: <p>I am using Zend Framework 2 and I have created a User Entity. Now I am trying to make the username field unique. However the following error is coming up.</p>
  
  <pre><code>[Semantical Error] The annotation "@UniqueEntity" in class User\Entity\User was never imported. Did you maybe forget to add a "use" statement for this annotation?
  </code></pre>
  
  <p>I have added this code for uniqueness check</p>
  
  <pre><code>@UniqueEntity("email")
  </code></pre>
  
  <p><strong>I can see that it is a method used in Symfony. How can I use it for Zend Framework 2?</strong></p>
  
  <p>This is the Entity I am using</p>
  
  <pre><code>&lt;?php
  
  namespace User\Entity;
  
  use Doctrine\ORM\Mapping as ORM,
      Zend\Form\Annotation;
  
  /**
   * A user entity.
   *
   * @ORM\Entity
   * @ORM\Table(name="users")
   * @UniqueEntity("email")
  
   * @property int $id
   * @property string $username
   * @property string $email
   * @property string $password
   * 
   * @Annotation\Name("User")
   */
  class User {
  
    /**
     * @ORM\Id
     * @ORM\Column(type="integer");
     * @ORM\GeneratedValue(strategy="AUTO")
     * 
     * @Annotation\Required(false)
     */
    protected $id;
  
    /**
     * @ORM\Column(type="string")
     * 
     * @Annotation\Attributes({"type":"text"})
     * @Annotation\Options({"label":"Username:"})
     * @Annotation\Filter({"name":"StringTrim"})
     * @Annotation\Filter({"name":"StripTags"})
     */
    protected $username;
  
    /**
     * @ORM\Column(type="string")
     * 
     * @Annotation\Attributes({"type":"text" })
     * @Annotation\Options({"label":"Email:"})
     * @Annotation\Filter({"name":"StringTrim"})
     * @Annotation\Filter({"name":"StripTags"})
     */
    protected $email;
  
    /**
     * @ORM\Column(type="string")
     * 
     * @Annotation\Attributes({"type":"text" })
     * @Annotation\Options({"label":"Password:"})
     * @Annotation\Filter({"name":"StringTrim"})
     * @Annotation\Filter({"name":"StripTags"})
     */
    protected $password;    
  
    public function __get($property) {
      return $this-&gt;$property;
    }
  
    /**
     * Magic setter to save protected properties.
     *
     * @param string $property
     * @param mixed $value
     */
    public function __set($property, $value) {
      $this-&gt;$property = $value;
    }
  
    public function getArrayCopy() {
      return array(
          'username' =&gt; $this-&gt;username,
          'email' =&gt; $this-&gt;email,
          'surname' =&gt; $this-&gt;surname,
          'first_name' =&gt; $this-&gt;first_name,
          'company' =&gt; $this-&gt;company,
          'postcode' =&gt; $this-&gt;postcode,
      );
    }
  
    public function populate($data) {
      $this-&gt;username = isset($data['username']) ? $data['username'] : $this-&gt;username;
    }
  
    public function setDate($property, $value){
      $this-&gt;$property = new \DateTime($value);
    }
  
  }
  </code></pre>