0

i am new to Doctrine2 and have created entitie-classes from my existing database using the following command:

.\vendor\bin\doctrine-module orm:convert-mapping --force --from-database annotation ./EXPORT/

Now i have my Classes and they are looking like this:

<?php

namespace App\Model\Entity; // this line was not generated automatically

use Doctrine\ORM\Mapping as ORM;

/**
 *
 * Category
 *
 * @ORM\Table(name="category")
 * @ORM\Entity
 */
 class Category
 {

     /**
     * @ORM\var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
     private $id;
 ....

Looks good, but i dont understand why there is "@ORM\" used before every notation in the docblocks. When i create queries they don't work until i remove this "@ORM\" bevore every notation. Did i miss something? I am not using any framework (Zend/Symfony...). I am just using "doctrine/orm": "~2.4" with composer.

Best regards Michael

1 Answers1

0

The ORM refers to the namespace shortcut at the top

use Doctrine\ORM\Mapping as ORM;

E.g. you could also use the Id annotation with the full namespace like that:

/**
* @Doctrine\ORM\Mapping\Id 
*/

Besides that I would recommend to take a look at the annotation docs to get doctrine running correctly

(http://doctrine-common.readthedocs.org/en/latest/reference/annotations.html and http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html)

Rob
  • 5,353
  • 33
  • 34
  • Thanks, but i still dont understand why i would need the Doctrine\ORM\Mapping namespace. My query: $qb ->select('c.name, c.description') ->from('App\Model\Entity\Category', 'c'); returns everything it should when i remove the ORM-namespace from the annotations and stops working when this namespace is there. Could you explain why this is the case? Till then i will go through the documentation you have sent once again, maybe i missed something... – user3741232 Mar 15 '15 at 18:57
  • I probably should read the error messages more carefully. I have found the solution here: http://stackoverflow.com/questions/15099060/doctrine2-class-is-not-a-valid-entity-or-mapped-super-class – user3741232 Mar 15 '15 at 19:49