I am following the book and on the page http://symfony.com/doc/current/book/doctrine.html
While following the book I am trying to work on relationship of product and cat
In book http://symfony.com/doc/current/book/doctrine.html entity Porduct has been manually created. You wrote code to Product.php. All information about entity fields contains in annotations.
But entity Category has been created with
php app/console doctrine:generate:entity --entity="AcmeStoreBundle:Category" --fields="name:string(255)"
Automatically generated entity Caterory.php doesn't contains annotations. Symfony stored information in "Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml".
That's why php app/console doctrine:mapping:info
says that you have only 1 mapped entity - Category.
Solving
You may generate Product entity with doctrine:generate:entity
or
Manually add information about Product entity to "Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml"
or
Delete "Acme\StoreBundle\Resources\config\doctrine\Category.orm.yml" and describe Category entity with annotations in Category.php
Check that the PHP opening and (optional) closing tags
<?php
and
?>
are correct in your file.
They are not included when you copy paste from the tutorial at http://symfony.com/doc/current/book/doctrine.html
I was stuck at the same problem. After looking at this post I started wondering why the syntax highlighting was broken and discovered that the opening and closing tags were missing. The error disappeared when the tags were included.
The solution:
Update symfony files:
composer update
then create entities
php bin/console doctrine:generate:entities BackendBundle
This error will also come up if your projects (only?) Entity is namespaced incorrectly. If you run the command
$ php app/console doctrine:generate:entities MyBundle
and it produces the error
[RuntimeException]
Bundle "MyBundle" does not contain any mapped entities.
Check the more specific command....
$ php app/console doctrine:generate:entities MyBundle:MyEntity
And see if you get the error:
[RuntimeException]
The autoloader expected class "MyBundle\Entity\MyEntity" to be defined in file "/path/to/MyBundle/Entity/MyEntity.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
If so, well then, the error speaks for itself (hopefully) and the namespace/class name needs to be corrected. Hopefully that is helpful to someone.
With
doctrine:generate:entity
you'll create new entity.
And when you add some attributes by hand with
doctrine:generate:entities AcmeDemoBundle:User
you'll create all accessor (getter and setter) of the entity User of AcmeDemoBundle
I personally had the error because I was missing the folder/directory "Entity".