“Class XXX is not a valid entity or mapped super c

2019-01-13 23:50发布

I had an entity class in Aib\PlatformBundle\Entity\User.php

I had no problems trying to create its form class through

php app/ console doctrine:generate:form AibPlatformBundle:User

Now I have change the namespace to Aib\PlatformBundle\Entity\Identity\User, but when I try to generate the form with the task I said before it says:

"Class Aib\PlatformBundle\Entity\User is not a valid entity or mapped super class."

This is the file content:

<?php
namespace Aib\PlatformBundle\Entity\Identity;

use Doctrine\ORM\Mapping as ORM;

    /**
     * Aib\PlatformBundle\Entity\Identity\User
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Aib\PlatformBundle\Entity\Identity
    \UserRepository")
     */
    class User
    {
    ...

Any idea?

symfony2.0.4

10条回答
Fickle 薄情
2楼-- · 2019-01-14 00:07

I resolved the same exception by deleting a conflicting autogenerated orm.php file in the bundle's Resources/config/doctrine folder; according to the documentation: "A bundle can accept only one metadata definition format. For example, it's not possible to mix YAML metadata definitions with annotated PHP entity class definitions."

查看更多
一夜七次
3楼-- · 2019-01-14 00:13

I resolved this issue by setting $useSimpleAnnotationReader=false when creating the MetaDataConfiguration.

查看更多
成全新的幸福
4楼-- · 2019-01-14 00:15

In my case the problem was solved by changing my servers cache from eAccelerator to APC. Apparently eAccelerator strips all the comments from files which breaks your annotations.

查看更多
smile是对你的礼貌
5楼-- · 2019-01-14 00:18

Had this problem yesterday and found this thread. I created the entity with the mapping in a new bundle (e.g. MyFooBundle/Entity/User.php), did all the configuration according to the docs but got the same error from above when trying to load the app.

In the end I realized that I wasn't loading MyFooBundle in AppKernel:

new My\FooBundle\MyFooBundle()

A great way to debug this is to run this command:

app/console doctrine:mapping:info
查看更多
疯言疯语
6楼-- · 2019-01-14 00:20

big thx to Mark Fu and mogoman

I knew it had to be somewhere in the config.yml... and being able to test it against the

app/console doctrine:mapping:info

really helped!

In fact, this command just simply stops at an error... no feedback, but when everything is fine you should be able to see all your entities listed.

查看更多
Explosion°爆炸
7楼-- · 2019-01-14 00:21

Had this problem - don't forget the annotation * @ORM\Entity like below:

/**
 * Powma\ServiceBundle\Entity\User
 *
 * @ORM\Entity
 * @ORM\Table(name="users")
 */
查看更多
登录 后发表回答