“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条回答
成全新的幸福
2楼-- · 2019-01-14 00:22

I got rid of the same error message as in your case by using app/console_dev instead of just app/console

查看更多
闹够了就滚
3楼-- · 2019-01-14 00:26

Do check your config.yml file, should be containing something like this:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        types:
            json: Sonata\Doctrine\Types\JsonType

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        # auto_mapping: true
        entity_managers:
            default:
                mappings:
                    FOSUserBundle: ~
                    # ApplicationSonataUserBundle: ~
                    YourUserBundle: ~
                    SonataUserBundle: ~

Add your own bundle to the mappings list.

查看更多
做个烂人
4楼-- · 2019-01-14 00:28

Very high possibility that you have PHP 5.3.16 (Symfony 2.x will not work with it). Anyway you should load check page on http://you.site.name/config.php If you had project not worked on hosting server, next lines must be removed in "config.php":

if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
    '127.0.0.1',
    '::1',
))) {
    header('HTTP/1.0 403 Forbidden');
    exit('This script is only accessible from localhost.');
}

Goodluck!

查看更多
放我归山
5楼-- · 2019-01-14 00:30

I solved this by passing false as the second parameter to Doctrine\ORM\Configuration::newDefaultAnnotationDriver.

It took me a while of digging through Google and source code.

My case was sort of special since I was using a mapping pointing to another directory unrelated to the Symfony installation as I also had to use legacy code.

I had refactored legacy entities and they stopped working. They used to use @Annotation instead of @ORM\Annotation, so after refactoring it simply failed to read the metadata. By not using a simple annotation reader, everything seems to be okayish.

查看更多
登录 后发表回答