5

So I'm trying to follow symfony2's tutorial on doctrine for my own website and modeling my User entity after their Product one.

Also, before anyone marks this a duplicate, I have already tried the solutions given in numerous other questions with no luck:

and the list goes on

I have my entity class:

<?php
    namespace MySite\MyBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /**
     * @ORM\Entity
     * @ORM\Table(name="user")
     */
    class User
    {
        /**
         * @ORM\Column(type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;

        /**
         * @ORM\Column(type="string", length=100)
         */
        protected $name;

        /**
         * @ORM\Column(type="string", length=64)
         */
        protected $password;
    }
?>

Now, I'm running the command:

$ php app/console doctrine:generate:entities MySite/MyBundle/Entity/User

to generate the accessor methods. However, when I do this, I get the error:

[Doctrine\ORM\Mapping\MappingException]
Class "MySite\MyBundle\Entity\User" is not a valid entity or mapped super class.
Community
  • 1
  • 1
user2443357
  • 127
  • 1
  • 1
  • 11
  • 1
    When you use php app/console doctrine:generate:entities - it means that you generate entity from database. But you create entity manualy and try to overwrite it. Run **php app/console doctrine:mapping:info** It will show you if you have problems in the mapping structure in doctrine – Dmitriy.Net Jan 02 '14 at 16:43
  • 1
    Thanks for the reply. Is the symfony tutorial wrong then? In the "Generating Getters and Setters" section, it says "doctrine:generate:entities" is to generate getters and setters. And when I run doctrine:mapping:info I get: [Exception] You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors. – user2443357 Jan 02 '14 at 17:46
  • http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html - tutorial – Dmitriy.Net Jan 02 '14 at 21:37
  • I'm not trying to generate them from a database, but from the PHP files. Anyways, I figured it out, I was missing a `auto_mapping: true` line in my config.yml; everything works as expected now. – user2443357 Jan 02 '14 at 22:29
  • Good. If user user2443357 gave correct answer, please set answer as "correct" – Dmitriy.Net Jan 03 '14 at 00:16
  • I just did, stackoverflow doesn't let you accept your own answer for 3 days – user2443357 Jan 06 '14 at 04:15

3 Answers3

4

Ok, I figured it out myself. My problem is that my config.yml was wrong. I was missing the auto_mapping: true line in my config.yml.

doctrine:
    # (dbal stuff here)

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

After adding that, everything auto-generates fine with the php app/console doctrine:generate:entities MySite/MyBundle/Entity/User line

user2443357
  • 127
  • 1
  • 1
  • 11
  • 5
    I am having the exact same issue as you, generating a simple entity from the Symfony2 book and failing. I did check auto_mapping and it didn't work for me. Hmm. – webkenny Jan 23 '15 at 14:05
0

I had a similar issue and I found at the end the problem in my case was I missed the class that extends Bundle

namespace Acme\TagBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeTagBundle extends Bundle
{
}

and declaring that class in AppKernel.php under the bundles array.

Sela Yair
  • 284
  • 2
  • 17
0

My problem was that I named the folder entity instead of Entity. When I fixed that it worked like a charm.

Vince Verhoeven
  • 1,693
  • 14
  • 25