error with ORM Mapping no doctrine 2

1

I am mapping the database with doctrine and am having a problem. When I use Annotations the following way works perfectly:

/**
 * @Entity
 * @Table(name="customer",uniqueConstraints={@UniqueConstraint(name="email", columns={"email"})})
 */
class Customer {
    (atributos)...
}

Well, I want to use use Doctrine\ORM\Mapping AS ORM; so that annotations starts with ORM\ Example:

use Doctrine\ORM\Mapping AS ORM;
/**
 * @ORM\Entity
 * @ORM\Table(name="customer",uniqueConstraints={@ORM\UniqueConstraint(name="email", columns={"email"})})
 */
class Customer {
    (atributos)...
}

But in this way the doctrine is not interpreting the class as a valid entity ...

Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class "Customer" is not a valid entity or mapped super class.'

My bootstrap.php looks like this

require_once "vendor/autoload.php";

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$entidades = array("entity/");
$isDevMode = true;

// configurações de conexão.
$dbParams = array(
'driver'   => 'pdo_mysql',
'host'     => 'localhost',
'user'     => 'root',
'password' => 'pass',
'dbname'   => 'LojaVirtual',
'charset'  => 'UTF8'
);    
//setando as configurações definidas anteriormente
$config = Setup::createAnnotationMetadataConfiguration($entidades, $isDevMode);   
//criando o Entity Manager com base nas configurações de dev e banco de dados
$entityManager = EntityManager::create($dbParams, $config);

Does anyone know how to solve this problem?

    
asked by anonymous 04.12.2014 / 16:15

1 answer

2

I was able to resolve by setting the last parameter ( $useSimpleReaderAnnotation ) of the call createAnnotationMetadataConfiguration as false :

$config = Setup::createAnnotationMetadataConfiguration($entidades, $isDevMode, null, null, false);

The point is that when this parameter is true (which is its default value), Doctrine does not understand when annotation classes are prefixed with @ORM and fail to pick up entity information.

This question helps you understand a little trouble.

    
05.12.2014 / 13:22