title: Doctrine, namespace and autoload entities
body: <p>I want to use Doctrine 2 in my project. I've some problems with it. I read the docs but probably I'm doing something wrong. </p>
  
  <p>I want to autoload entities classes. And method from the docs is not working.</p>
  
  <p>My bootstrap.php</p>
  
  <pre><code>&lt;?php
  
  require_once "vendor/autoload.php";
  use Doctrine\ORM\Tools\Setup;
  use Doctrine\ORM\EntityManager;
  use Doctrine\ORM\Mapping\Driver;
  
  $paths = array("../Entities");
  $isDevMode = false;
  
  $classLoader = new \Doctrine\Common\ClassLoader('Entities','../Entities');
  $classLoader-&gt;register();
  
  // the connection configuration
  $dbParams = array(
      'driver'   =&gt; 'pdo_mysql',
      'user'     =&gt; 'xxx',
      'password' =&gt; 'xxx',
      'dbname'   =&gt; 'xxx',
  );
  
  $driver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(new Doctrine\Common\Annotations\AnnotationReader(),array('../Entities'));
  $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
  $config-&gt;setMetadataDriverImpl($driver);
  $em = EntityManager::create($dbParams, $config);
  </code></pre>
  
  <p>I've got my model's classes in Entities directory. I've generated them using doctrine client. They looks OK. There are ids, setters, getters and namespace at the beginning. </p>
  
  <p>/Entities/ArticleCat.php</p>
  
  <pre><code>&lt;?php
  
  namespace Entities;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * ArticleCat
   *
   * @ORM\Table(name="article_cat")
   * @ORM\Entity
   */
  class ArticleCat
  {
  </code></pre>
  
  <p>My script where I want to use doctrine:</p>
  
  <pre><code>&lt;?php
    require_once 'bootstrap.php';
  
    $article = $em-&gt;find('ArticleCat', 21);
    echo $article-&gt;getName();
  </code></pre>
  
  <p>It's not working. It works only when I use it this way and I <strong>remove namespace from Entity model</strong>.</p>
  
  <pre><code>&lt;?php
    require_once 'bootstrap.php';
    require_once 'Entities/ArticleCat.php'; //this line added (manual load)
  
  
    $article = $em-&gt;find('ArticleCat', 21);
    echo $article-&gt;getName();
  </code></pre>
  
  <p>What's the proper way of using doctrine and autoload entities? Why the namespace is a problem?</p>
  
  <p>My errors:</p>
  
  <pre><code>Fatal error: Uncaught exception 'Doctrine\Common\Persistence\Mapping\MappingException' 
  with message 'Class 'ArticleCat' does not exist' in 
  /myproject/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:96
  Stack trace: #0 /myproject/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php(40): 
  Doctrine\Common\Persistence\Mapping\MappingException::nonExistingClass('ArticleCat') 
  #1 /myproject/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping
     /AbstractClassMetadataFactory.php(267): Doctrine\Common\Persistence\Mapping
     \RuntimeReflectionService-&gt;getParentClasses('ArticleCat') 
  #2 /myproject/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping
     /AbstractClassMetadataFactory.php(297): Doctrine\Common\Persistence\Mapping
     \AbstractClassMetadataFactory-&gt;getParentClasses('ArticleCat') 
  #3 /myproject/vendor/doc in /myproject/vendor/doctrine/common/lib/Doctrine/Common/Persistence
     /Mapping/MappingException.php on line 96
  </code></pre>