2014-10-02 02:57

使用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;
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanguan1573 duanguan1573 7年前

    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

    点赞 评论 复制链接分享
  • dongzhi2332 dongzhi2332 7年前

    Have you tried using following console command ?

    $ php app/console doctrine:generate:entities MyApp/MyBundle/Model

    I hope it will work. Your entity namespace is different than Acme/StoreBundle/Entity/Product. Your entities are in Model directory/namespace so you should use first argument of command a valid namespace. So that following cmd generates error as you have mentioned above.

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

    点赞 评论 复制链接分享