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.

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

报告相同问题?

悬赏问题

  • ¥20 Html备忘录页面制作
  • ¥15 黄永刚的晶体塑性子程序中输入的材料参数里的晶体取向参数是什么形式的?
  • ¥20 数学建模来解决我这个问题
  • ¥15 计算机网络ip分片偏移量计算头部是-20还是-40呀
  • ¥15 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 django5安装失败