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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!