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

        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%"

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

Model class


// 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="")
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

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

    Read this maybe it can help:

    Doctrine Mapping in Symfony2 using YAML

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



  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗