<p dir="auto">This constraint was thought-out to be used directly on a entity. But in several cases, i used it without a doctrine entity, for example when the form has fields for diferents entities.</p>
<p dir="auto">In this case i want to have the way to specify not only the field also the entity that belongs the field.</p>
<p dir="auto">I think that the change will be easy, so i will send a PR soon.</p>
<p dir="auto">I think that the PR will be on 2.8 it is?</p>
<p dir="auto">Regards!</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes/no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>yes/no</td>
</tr>
<tr>
<td>RFC?</td>
<td>yes</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.2.0</td>
</tr>
</tbody>
</table>
<p dir="auto">I wonder how this should work for very common example using DTOs for forms. I have applied validation to my DTO</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="AppBundle\Command\Register:
    constraints:
            - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
                fields: email
                entityClass: AppBundle\Entity\User
                em: default"><pre class="notranslate"><code class="notranslate">AppBundle\Command\Register:
    constraints:
            - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
                fields: email
                entityClass: AppBundle\Entity\User
                em: default
</code></pre></div>
<p dir="auto">With this configuration I get error: "The class 'AppBundle\Command\Register' was not found in the chain configured namespaces AppBundle\Entity"</p>
<p dir="auto">The flow currently works like this I set <code class="notranslate">em</code> for my entity:  <code class="notranslate">AppBundle\Entity\User</code> but in validator we have getting current class metadata for main entity (in my example AppBundle\Command\Register this is not an entity) $em-&gt;getClassMetadata(get_class($entity)); so this is why it fails.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator

        if ($constraint-&gt;em) {
            $em = $this-&gt;registry-&gt;getManager($constraint-&gt;em);

            if (!$em) {
                throw new ConstraintDefinitionException(sprintf('Object manager &quot;%s&quot; does not exist.', $constraint-&gt;em));
            }
        } else {
            $em = $this-&gt;registry-&gt;getManagerForClass(get_class($entity));

            if (!$em) {
                throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class &quot;%s&quot;.', get_class($entity)));
            }
        }

        $class = $em-&gt;getClassMetadata(get_class($entity));
        /* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */"><pre class="notranslate"><code class="notranslate"># Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator

        if ($constraint-&gt;em) {
            $em = $this-&gt;registry-&gt;getManager($constraint-&gt;em);

            if (!$em) {
                throw new ConstraintDefinitionException(sprintf('Object manager "%s" does not exist.', $constraint-&gt;em));
            }
        } else {
            $em = $this-&gt;registry-&gt;getManagerForClass(get_class($entity));

            if (!$em) {
                throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', get_class($entity)));
            }
        }

        $class = $em-&gt;getClassMetadata(get_class($entity));
        /* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */
</code></pre></div>
<p dir="auto">IMHO if we specify entityClass we should expect that everything will concern this entityClass. Another example of failure is when two entities: entity1 and entity2 belong to different entity managers. If this is an expected behaviour (IMHO it should work like this) we should at least add this information to documentation ?</p>