title: Combining @Gedmo\NestedTree and @ORM\UniqueEntity
body: <p>I'm creating a folder structure implemented with the <a href="https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/tree.md" rel="nofollow" title="NestedTree">NestedTree</a> behaviour.
  Furthermore, I don't want that two folders may have the same name if they are siblings.
  For this, I use the combination of <code>@UniqueEntity</code> and <code>@UniqueConstraint</code> annotations, but it does not work.</p>
  
  <p>First my entity (stripped to the minimum since it is 100% identical to the NestedTree defaults) :</p>
  
  <pre class="lang-php prettyprint-override"><code>/**
   * @ORM\Entity
   * @Gedmo\Tree(type="nested")
   * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
   * @UniqueEntity(fields={"parent", "name"})
   * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="uniq_url", columns={"parent_id", "name"})})
   */
  class Folder
  {
      /**
       * @ORM\Column(type="string", nullable=false)
       */
      protected $name;
  
      /**
       * @Gedmo\TreeParent
       * @ORM\ManyToOne(targetEntity="Folder", inversedBy="children")
       * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
       */
      protected $parent;
  }
  </code></pre>
  
  <h2>First try (ignoreNull = true)</h2>
  
  <p>When I create two folders with the same name, I have an integrity constraint violation, meaning that the <code>@UniqueConstraints</code> in the database worked but that the <code>@UniqueEntity</code> didn't :</p>
  
  <pre><code>Integrity constraint violation: 1062 Duplicate entry 'name_of_folder' for key 'uniq_url' 
  </code></pre>
  
  <h2>Second try (ignoreNull = false)</h2>
  
  <p>I also tried with the ignoreNull key set to false (the default is true) :</p>
  
  <pre class="lang-php prettyprint-override"><code>@UniqueEntity(fields={"parent", "name"}, ignoreNull=false)
  </code></pre>
  
  <p>but then I get this error :</p>
  
  <pre><code>Warning: ReflectionProperty::getValue() expects parameter 1 to be object, null given in vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 670
  </code></pre>
  
  <p>I've nailed the error down to these lines in <code>Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator</code> :</p>
  
  <pre class="lang-php prettyprint-override"><code>        $criteria[$fieldName] = $class-&gt;reflFields[$fieldName]-&gt;getValue($entity);
  
          if ($constraint-&gt;ignoreNull &amp;&amp; null === $criteria[$fieldName]) {
              return;
          }
  
          if ($class-&gt;hasAssociation($fieldName)) {
              /* Ensure the Proxy is initialized before using reflection to
               * read its identifiers. This is necessary because the wrapped
               * getter methods in the Proxy are being bypassed.
               */
              $em-&gt;initializeObject($criteria[$fieldName]);
  
              $relatedClass = $em-&gt;getClassMetadata($class-&gt;getAssociationTargetClass($fieldName));
              //problem
              $relatedId = $relatedClass-&gt;getIdentifierValues($criteria[$fieldName]);
  
              if (count($relatedId) &gt; 1) {
                  throw new ConstraintDefinitionException(
                      "Associated entities are not allowed to have more than one identifier field to be " .
                      "part of a unique constraint in: " . $class-&gt;getName() . "#" . $fieldName
                  );
              }
              $criteria[$fieldName] = array_pop($relatedId);
          }
  </code></pre>
  
  <p>The problem appears on the line marked with <code>//problem</code>. It appears that <code>$criteria[$fieldName] === null</code> is the reason of the error.</p>
  
  <p>So here I am, not knowing what to do...
  Does anybody have an idea on what's going on ?</p>
  
  <p>Thank you.</p>