1
I’m mapping the database with Doctrine and I’m having a problem. When I use the Annotations as follows it works perfectly:
/**
* @Entity
* @Table(name="customer",uniqueConstraints={@UniqueConstraint(name="email", columns={"email"})})
*/
class Customer {
(atributos)...
}
Well, I want to use the use Doctrine\ORM\Mapping AS ORM;
so that the annotations
start 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 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 is as follows
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?
How is the namespace organization of your project? I believe that for some reason Doctrine may be looking for the class
ORM\Entity
within the namespaces of its entities.– Rodrigo Rigotti
I really don’t know if this is it, because this mistake is common when I forget to declare the
@Entity
in the first case, already the namespaces he is recognizing normally, the autoload is the way that the Composer created pro Doctrine and I only acquired the classmap of the entities... It has recognized all classes normally when it comes to bootstrap.php or the test.php file– RodrigoBorth
@Rodrigorigotti no new idea?
– RodrigoBorth
can host your code somewhere so I can test it?
– Rodrigo Rigotti
I’ll pass the project to git
– RodrigoBorth
@Rodrigorigotti u.u a part of the project is not giving to publish, as soon as I get notice
– RodrigoBorth
@RodrigoRigotti https://github.com/rodrigoborth/LojaVirtual2
– RodrigoBorth
I’ve already been able to reproduce. I’m testing.
– Rodrigo Rigotti