<p dir="auto">use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;</p>
<p dir="auto">// ...</p>
<ul dir="auto">
<li>
<p dir="auto">@UniqueEntity("email")</p>
</li>
<li>
<p dir="auto">@UniqueEntity("token")<br>
<em>/<br>
class UserBack implements UserInterface<br>
{<br>
/</em>*</p>
<ul dir="auto">
<li><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Orm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Orm">@Orm</a>\Column(type="string", unique = true)</li>
<li><a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/Assert/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Assert">@Assert</a>\NotBlank</li>
<li><a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/Assert/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Assert">@Assert</a>\Email<br>
*/<br>
protected $email;</li>
</ul>
<p dir="auto">/**</p>
<ul dir="auto">
<li><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Orm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Orm">@Orm</a>\Column(type="string", unique = true)</li>
<li><a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/Assert/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Assert">@Assert</a>\NotBlank</li>
<li><a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/Assert/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Assert">@Assert</a>\MaxLength(50)<br>
*/<br>
private $token;</li>
</ul>
<p dir="auto">// ...<br>
}</p>
</li>
</ul>
<p dir="auto">It does generate just one key for email and returns duplicate entry for token.</p>
<p dir="auto">doctrine:schema:update --dump-sql<br>
CREATE UNIQUE INDEX UNIQ_92F7742EE7927C74 ON UserBack (email);<br>
CREATE UNIQUE INDEX UNIQ_92F7742E5F37A13B ON UserBack (token)</p>
<p dir="auto">doctrine:schema:update --force<br>
Updating database schema...<br>
[PDOException]<br>
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'UNIQ_92F</p>
<p dir="auto">I downloaded Symfony 2.6.1 and added only a bit of code within one of the default built-in bundles.</p>
<p dir="auto">I have a very simple entity:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class SomeEntity
{
    private $firstName;

    public function setFirstName($firstName) {
        $this-&gt;firstName = $firstName;
    }
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">SomeEntity</span>
{
    <span class="pl-k">private</span> <span class="pl-c1"><span class="pl-c1">$</span>firstName</span>;

    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">setFirstName</span>(<span class="pl-s1"><span class="pl-c1">$</span>firstName</span>) {
        <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">firstName</span> = <span class="pl-s1"><span class="pl-c1">$</span>firstName</span>;
    }
}</pre></div>
<p dir="auto">I created a simple <code class="notranslate">validation.yml</code> for the <code class="notranslate">$firstName</code> property:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="//src\Acme\DemoBundle\Resources\config\validation.yml
Acme\DemoBundle\Entities\SomeEntity:
    properties:
        firstName:
            - NotBlank: ~"><pre class="notranslate"><code class="notranslate">//src\Acme\DemoBundle\Resources\config\validation.yml
Acme\DemoBundle\Entities\SomeEntity:
    properties:
        firstName:
            - NotBlank: ~
</code></pre></div>
<p dir="auto">Within the Controller method I simply added:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$validator = $this-&gt;get('validator');

$entity = new SomeEntity();
$entity-&gt;setFirstName('haha');

$errors = $validator-&gt;validate($entity);

if (count($errors) &gt; 0) {
    $errorsString = (string) $errors;
    return new Response($errorsString, Response::HTTP_BAD_REQUEST);
}

return new Response('everything ok yeey', Response::HTTP_OK);"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>validator</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">get</span>(<span class="pl-s">'validator'</span>);

<span class="pl-s1"><span class="pl-c1">$</span>entity</span> = <span class="pl-k">new</span> <span class="pl-v">SomeEntity</span>();
<span class="pl-s1"><span class="pl-c1">$</span>entity</span>-&gt;<span class="pl-en">setFirstName</span>(<span class="pl-s">'haha'</span>);

<span class="pl-s1"><span class="pl-c1">$</span>errors</span> = <span class="pl-s1"><span class="pl-c1">$</span>validator</span>-&gt;<span class="pl-en">validate</span>(<span class="pl-s1"><span class="pl-c1">$</span>entity</span>);

<span class="pl-k">if</span> (count(<span class="pl-s1"><span class="pl-c1">$</span>errors</span>) &gt; <span class="pl-c1">0</span>) {
    <span class="pl-s1"><span class="pl-c1">$</span>errorsString</span> = (<span class="pl-smi">string</span>) <span class="pl-s1"><span class="pl-c1">$</span>errors</span>;
    <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-v">Response</span>(<span class="pl-s1"><span class="pl-c1">$</span>errorsString</span>, <span class="pl-v">Response</span>::<span class="pl-c1">HTTP_BAD_REQUEST</span>);
}

<span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-v">Response</span>(<span class="pl-s">'everything ok yeey'</span>, <span class="pl-v">Response</span>::<span class="pl-c1">HTTP_OK</span>);</pre></div>
<p dir="auto">Now, I run all this on Windows 7 which has a XAMPP installation. Everything works fine.</p>
<p dir="auto">But, if I turn off MySQL, I get an exception:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="An exception occured in driver: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it."><pre class="notranslate"><code class="notranslate">An exception occured in driver: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
</code></pre></div>
<p dir="auto">The stack trace reveals that <code class="notranslate">Validator\Validator\RecursiveContextualValidator-&gt;validateClassNode::489</code> calls <code class="notranslate">Symfony\Bridge\Doctrine\Validator\DoctrineInitializer-&gt;initialize</code>, which is probably why Symfony tries to reach the database.</p>
<p dir="auto">Since I wrote absolutely no code that deals with databases, should this be allowed or somehow disabled/bypassed ?</p>
<p dir="auto">I only want to do some extensive tests on the Validator component, I don't get why database access is needed for this.</p>