douqun1977 2014-10-02 02:57
浏览 39
已采纳

使用php app / console时,“类XXX不是有效实体或映射超类”错误

I'm following this Symfony2/Doctrine guide and I've come to the part where I need to create getters/setters. but I am stuck with this part:

$ php app/console doctrine:generate:entities Acme/StoreBundle/Entity/Job

I've searched the net for possible solutions (seems to mainly revolve around using 2 asterisks for the start) but couldn't find the solution.

Some info:

  1. Bundle is properly loaded (via AppKernel.php) as I have a test "hello world" and that works.
  2. The namespace path is correct
  3. Job.php exists in the right folder
  4. I'm using postgres as my database. I'm not sure if this matters.
  5. I have tried with and without the use Doctrine\ORM\Mapping line in model class (see below for code)
  6. I don't think I'm running a accelerator at least according to get_loaded_extensions function Any ideas would be very helpful.

Thanks a lot :)

snippet of my settings.yml

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

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

Model class

<?php

// src/MyApp/MyBundle/Model/Job.php

namespace MyApp\MyBundle\Model;

use Doctrine\ORM\Mapping as ORM;

/**
 * MyApp\MyBundle\Model\Job
 *
 * @ORM\Entity
 * @ORM\Table(name="myschema.jobs")
 */
class Job {
    /**
     * @ORM\Column(name="job_id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $jobid;

    /**
     * @ORM\Column(name="name", type="text")
     */
    protected $name;

    /**
     * @ORM\Column(name="job_desc", type="text")
     */
    protected $description;

    /**
     * @ORM\Column(name="personal_req", type="text")
     */
    protected $requirements;
}
  • 写回答

2条回答 默认 最新

  • duanguan1573 2014-10-02 06:53
    关注

    did you create your entity using doctrine? I saw on your Job.php entity you are using annotation as mapping format.

    In error output it said doctrine can't find any mapped entities. I've been there and it solved with specific configuration of your config.yml.

    Try to change this on your config.yml

    doctrine:
    dbal:
        driver:   "%database_driver%"
        #etc
    
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: false
        mappings:
            MyAppMyBundle:
                type: annotation #On your case it should be annotation
                dir: Resources/Model/
    

    Read this maybe it can help:

    Doctrine Mapping in Symfony2 using YAML

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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键失灵