I get exception Uncaught exception \'Doctrine\\ORM\\Mapping\\MappingException\' with message \'Class \"Users\" is not a valid entity or mapped super class
every
You are using a Doctrine\Common\Annotations\SimpleAnnotationReader
instead of a Doctrine\Common\Annotations\AnnotationReader
.
The SimpleAnnotationReader
works with default namespaces and reads annotations in format @Entity
, while the AnnotationReader
can use the imported classes and namespaces (via use statement) and annotations such as @ORM\Entity
.
You can read more about that on the documentation.
Here's a fixed version of your test.php
'pdo_mysql',
'user' => 'root',
'password' => 'pass',
'dbname' => 'dbname',
);
$config = Setup::createConfiguration($isDevMode);
$driver = new AnnotationDriver(new AnnotationReader(), $paths);
// registering noop annotation autoloader - allow all annotations by default
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$em = EntityManager::create($connectionParams, $config);
$user = $em->find('Users', 5);