title: Check database field in entity on Symfony platform
body: <p>When my controller request the new account the entity generates automatically it's customer ID. This is done with the following code:</p>
  
  <pre><code>/**
   * Set custId
   *
   * @param integer $custId
   * @return Account
   */
  private function setCustId()
  {
      $this-&gt;custId = rand(1000, 9999);
  
      return $this;
  }
  </code></pre>
  
  <p>Only in this entity I want to check if there is already a customer in the database. So adding the following code and repeating this until a free ID if found. But already tried to access the database with the code below, but i'm getting an php error. Anyone some idee?</p>
  
  <pre><code> $account = $this-&gt;getDoctrine()
              -&gt;getRepository('MyBundle:Account')
              -&gt;findOneBy(array('custId' =&gt; $this-&gt;custId));
  </code></pre>