duandu1966 2014-09-29 08:16
浏览 45
已采纳

Symfony2类不是有效实体或映射超类

I'm new to symfony2 and trying to execte the command in neatbeans

console doctrine:generate:entities /backend/storeBundle/Entity/RolClass

it's shown the error:

[Doctrine\ORM\Mapping\MappingException]
Class "\backend\storeBundle\Entity\RolClass" is not a valid entity or 
mapped super class.                                                               

The class:

<?php
namespace backend\storeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity
* @ORM\Table(name="nomrol")
*/
  class RolClass {
/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;
/**
 * @ORM\Column(type="string",length=100)
 */
protected $namerolcust;
}

Searching info in this page I tried to modify the app/config.yml:

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: default
    entity_managers:
        default:
            mappings:
                backendstoreBundle: ~
  • 写回答

1条回答 默认 最新

  • duanbai5348 2014-09-29 09:31
    关注

    Firstly it is bad practice to use CLass in you class name, please remove ;)

    1) do the above an then re-run

    2) If that still fails then for some reason then alter you config.yml to

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

    Now if that fails for some strange reason you doctrine is looking for a superclass so you will have to do the following.

    Define the base-class:

    /**
     * @ORM\MappedSuperclass
     */
    abstract class BaseRol
    {
        // base rol
    }
    

    Then extend your class

    /**
     * @ORM\Entity
     */
    class Rol extends Baserol
    {
        // rol
    }
    

    Because you're missing the @MappedSuperclass annotation on the base-class, Doctrine throws the exception you mention.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵