Error:
Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class models\repositories\UserRepository is not a valid entity or mapped super class.' in ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ Mapping\MappingException.php:142 Stack trace: #0 htdocs\DoCI\application\libraries\Doctrine\ORM\Map ping\Driver\AnnotationDriver.php(148): Doctrine\ORM\Mapping\MappingException::classIsNotA ValidEntityOrMappedSuperClass('models\reposito...' ) #1 ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ Mapping\ClassMetadataFactory.php(281): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('models\reposito...', Object(Doctrine\ORM\Mapping\ClassMetadata)) #2 ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ Mapping\ClassMetadataFactory.php(170): Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('models\reposito...') #3 ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ EntityManager.php(257): Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor('models\ in ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ Mapping\MappingException.php on line 142
Bueno comentare como tengo mi estructura en mi proyecto:
(Caperta-->models)
--> (Capeta-->repositories)
--> UserRepository.php (models-->repositories-->UserRepository )
--> User.php (models-->User )
La Clase User
(models-->User.php)
Código PHP:
   namespace models;
use DoctrineCommonCollectionsArrayCollection;
/**
 * @Entity
 * @Table(name="usuarios")
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="tipo_usuario", type="string")
 * @DiscriminatorMap({"user" = "User", "ROLE_CLIENTE" = "Cliente"})
 * @entity(repositoryClass="models\repositories\UserRepository")
 */
class User
{
   
    /**
     * @Id
     * @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @Column(type="string", length=32, nullable=false)
     */
    protected $username;
    /**
     * @Column(type="string", length=64, nullable=false)
     */
    protected $password;
    /**
     * @Column(type="string", length=255, nullable=false)
     */
    protected $email;
} 
    La Clase UserRepository
(models-->reposotories->UserRepository.php)
Código PHP:
   <?php
namespace modelsrepositories;
use DoctrineORMEntityRepository;
class UserRepository extends EntityRepository {
        
    function validate(){
        
        $em = $this->getEntityManager();
        $em->createQuery('SELECT u FROM models\User u WHERE u.username = "Cliente"')->getResult();
        
    }
}
?>    Dentro de mi controlador, esta es una de las tantas maneras que he intentado llamar al repositorio
Código PHP:
            $em = $this->doctrine->em;
        $user = $em->getRepository('models\repositories\UserRepository')
                           ->validate(); 
    Código PHP:
   <?php
use DoctrineORMEntityManager,
    DoctrineORMConfiguration;
define('DEBUGGING', FALSE);
class Doctrine {
    public $em = null;
    public function __construct()
    {
        // load database configuration and custom config from CodeIgniter
        require APPPATH . 'config/database.php';
        // Set up class loading.
        require_once APPPATH . 'libraries/Doctrine/Common/ClassLoader.php';
        $doctrineClassLoader = new DoctrineCommonClassLoader('Doctrine', APPPATH . 'libraries');
        $doctrineClassLoader->register();
        $entitiesClassLoader = new DoctrineCommonClassLoader('models', rtrim(APPPATH, '/'));
        $entitiesClassLoader->register();
        $proxiesClassLoader = new DoctrineCommonClassLoader('Proxies', APPPATH . 'models');
        $proxiesClassLoader->register();
        $symfonyClassLoader = new DoctrineCommonClassLoader('Symfony', APPPATH . 'libraries/Doctrine');
        $symfonyClassLoader->register();
//                $entityClassLoader = new \Doctrine\Common\ClassLoader('repositories', APPPATH.'models');
//                $entityClassLoader->register();
        // Choose caching method based on application mode
        if (ENVIRONMENT == 'production')
        {
            $cache = new DoctrineCommonCacheApcCache;
        }
        else
        {
            $cache = new DoctrineCommonCacheArrayCache;
        }
        // Set some configuration options
        $config = new Configuration;
        // Metadata driver
        $driverImpl = $config->newDefaultAnnotationDriver(APPPATH . 'models');    
        $config->setMetadataDriverImpl($driverImpl);
        // Caching
        $config->setMetadataCacheImpl($cache);
        $config->setQueryCacheImpl($cache);
        // Proxies
        $config->setProxyDir(APPPATH . 'models/Proxies');
        $config->setProxyNamespace('Proxies');
        if (ENVIRONMENT == 'development') {
            $config->setAutoGenerateProxyClasses(TRUE);
        } else {
            $config->setAutoGenerateProxyClasses(FALSE);
        }
        // SQL query logger
        if (DEBUGGING)
        {
            $logger = new DoctrineDBALLoggingEchoSQLLogger;
            $config->setSQLLogger($logger);
        }
        // Database connection information
        $connectionOptions = array(
            'driver' => 'pdo_mysql',
            'user' => $db['default']['username'],
            'password' => $db['default']['password'],
            'host' => $db['default']['hostname'],
            'dbname' => $db['default']['database']
        );
        // Create EntityManager
        $this->em = EntityManager::create($connectionOptions, $config);
    }
}    
 


