类 ..Entity\User 不是有效的实体或映射的超类

发布于 2024-12-13 11:46:56 字数 1061 浏览 0 评论 0原文

当我尝试清除缓存时出现此错误(例如):

[Doctrine\ORM\Mapping \MappingException] 类 Aib\PlatformBundle\Entity\User 不是有效实体或映射的超级 类。

这是User.php:

<?php
// src/Aib/PlatformBundle/Entity/User.php

namespace Aib\PlatformBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

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

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

}

这是User.php 存储的地方:

javier@javier:~/programacion/aib/src/Aib/PlatformBundle/Entity$ ls User.php UserRepository.php

这是AppKernel.php:

public function registerBundles()
{
    $bundles = array(
        ...
        new Aib\PlatformBundle\AibPlatformBundle(),
        ...
    );

sf 2.0.4

I'm getting this error when I try to clear the cache (for example):

[Doctrine\ORM\Mapping \MappingException] Class
Aib\PlatformBundle\Entity\User is not a valid entity or mapped super
class.

This is User.php:

<?php
// src/Aib/PlatformBundle/Entity/User.php

namespace Aib\PlatformBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

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

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

}

And this is the place where User.php is stored:

javier@javier:~/programacion/aib/src/Aib/PlatformBundle/Entity$ ls
User.php UserRepository.php

This is the AppKernel.php:

public function registerBundles()
{
    $bundles = array(
        ...
        new Aib\PlatformBundle\AibPlatformBundle(),
        ...
    );

sf 2.0.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

辞别 2024-12-20 11:46:56

就我而言,我的类定义中缺少 * @ORM\Entity

/**
 * @ORM\Entity
 * @ORM\Table(name="listtype")
 */
class ListType
{
    ...
}

In my case I was missing * @ORM\Entity in my class definition.

/**
 * @ORM\Entity
 * @ORM\Table(name="listtype")
 */
class ListType
{
    ...
}
风吹雪碎 2024-12-20 11:46:56

我在实施 FOS UserBundle 时有完全相同的经历,并发现我能够通过删除 MyBundle\Resources\config\doctrine 文件夹来解决该问题。

我不完全理解原因(新手),但认为问题是由于以麻烦的方向构建数据库内容的结果,即从条令实体和通过逆向工程一些表。

I had the exact same experience with my implementation of the FOS UserBundle and found I was able to resolve the issue by removing the MyBundle\Resources\config\doctrine folder.

I dont fully understand the cause (newbie) but think the issue is a result of having database content built in bother directions, ie from doctrine entities and by reverse engineering some tables.

风筝在阴天搁浅。 2024-12-20 11:46:56

我遇到了同样的问题,结果是 app/config/config.yml

它需要默认包的定义,如下所示 NameBundle,然后它工作正常

orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: default
    entity_managers:
      default:
        mappings:
          NameBundle: ~

I had the same problem and it turned out to be the app/config/config.yml

It needed the defintion of the default bundle as below NameBundle, then it worked fine

orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: default
    entity_managers:
      default:
        mappings:
          NameBundle: ~
氛圍 2024-12-20 11:46:56

就我而言,通过将服务器缓存从eAccelerator更改为APC解决了问题。
显然,eAccelerator 会从文件中删除所有会破坏注释的注释。

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.

丿*梦醉红颜 2024-12-20 11:46:56

我遇到了同样的错误,但这是因为我没有包含 Sonata 应用程序:

尝试以下操作:

在 AppKernel.php 中添加一行

$bundles = array(
...
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
...

I had the same error, but this was because I wasn't including the Sonata Application:

try this:

add a line to your AppKernel.php

$bundles = array(
...
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
...
猫烠⑼条掵仅有一顆心 2024-12-20 11:46:56

如果继承自映射类,则可以在实体的注释中添加@ORM\SuperMappedClass。
您可以在 这篇文章

If you inherited from mapped class, you can add @ORM\SuperMappedClass in entity's annotation.
You can read most information in this article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文