Doctrine2 - "Class" Is Not a Valid Entity or Mapped Super Class

Doctrine2 - class is not a valid entity or mapped super class

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

<?php

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/entities/Users.php';

$paths = array(__DIR__ . '/entities');
$isDevMode = false;
$connectionParams = array(
'driver' => '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);

Symfony Doctrine ORM not a valid entity or mapped super class

May be datetime field has same name as function/implementation in doctrine, I have got same mistake by naming a table "condition" which may be condition function in MySql query



Related Topics



Leave a reply



Submit