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 matlab基于鲸鱼算法优化vmd
  • ¥20 PCB设计与制作问答
  • ¥20 课堂跑如何下载ppt
  • ¥15 有没有哥看着画下电路
  • ¥15 STM32阿里云平台显示不了传感器采集的数据
  • ¥20 三菱FX系列PLC上位机串口下指令置位M64和M65,这两条指令分别是什么呢?
  • ¥15 有关结冰模拟程序咨询
  • ¥15 ubuntu服务器配置dns域名后无法访问其他域名
  • ¥50 本人复制了一个关于股票指标的代码,但是运行失败,有没有人帮我解决一下
  • ¥50 用matlab和numeca做透平机械流体力学和热力学模拟 价格可议