symfony2错误:[RuntimeException]命名空间" ProjectBundle \ Entity \ Mandator"不包含任何映射的权限

时间:2015-01-24 14:08:17

标签: symfony doctrine-orm one-to-many setter getter

我在Symfony2中的OneToMany关系中遇到问题。我创建了实体

委托人

// src/Pso/ProjectBundle/Entity/Mandator.php
   namespace Pso\ProjectBundle\Entity;

   use Doctrine\Common\Collections\ArrayCollection;
   use Doctrine\ORM\Mapping as ORM;

   /**
    * @ORM\Table(name="mandator", options={"collate"="utf8_general_ci",
                 "charset"="utf8", "engine"="InnoDB"})
    * @ORM\Entity()
    */

   class Mandator
  {     
    /**
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id()
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    private $id;


   /**
    * @ORM\OneToMany(targetEntity="Pso\ProjectBundle\Entity\Project",   
      mappedBy="mandator")
    */
    private $projects;

  /**
   * @ORM\Column(type="string", length=50, nullable=false)
   */
   private $longname;

  /**
   * @ORM\Column(type="string", length=50, nullable=false)
   */
  private $shortname;

  public function __construct() {
    $this->projects = new ArrayCollection();
  }
}

和实体Project,wgich与另一个名为User

的实体有关系
// src/Pso/ProjectBundle/Entity/Project.php
namespace Pso\ProjectBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="project", options={"collate"="utf8_general_ci", 
             "charset"="utf8", "engine"="InnoDB"})
 * @ORM\Entity(repositoryClass="Pso\ProjectBundle\Entity\ProjectRepository")
 * @ORM\Entity()
 */

class Project
{ 
  /**
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id()
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;

 /**
 * @ORM\Column(type="string", length=255, unique=true, nullable=false)
 */
 private $project_nr;

 /**
 * @ORM\ManyToOne(targetEntity="Pso\ProjectBundle\Entity\Mandator",  
                  inversedBy="projects")
 * @ORM\JoinColumn(name="mandator_id", referencedColumnName="id")
 */
 private $mandator;

 /**
 * @ORM\Column(type="string", length=80, nullable=false)
 */
 private $project_name;

 /**
 * @ORM\Column(type="string", length=50)
 */
 private $customer;

 /**
 * @ORM\Column(type="string", length=50)
 */
 private $label;

 /**
 * @ORM\Column(type="date")
 */
 private $shipping_date;

/**
 * @ORM\Column(type="float")
 */ 
 private $advance_payment;

 /**
 * @ORM\Column(type="integer", length=1)
 */
 private $probability;

 /**
 * @ORM\Column(type="blob")
 */
 private $special_demand;

/**
 * @ORM\Column(type="string", length=4)
 */ 
 private $currency;

/**
 * @ORM\Column(type="integer", length=1, nullable=false)
 */ 
 private $status;

/**
 * @ORM\Column(type="string", length=100)
 */  
 private $contract_nr;

/**
 * @ORM\Column(type="datetime", nullable=false)
 */   
 private $dbinsert;

 /**
 * @ORM\Column(type="datetime", nullable=false)
 */ 
 private $dbupdate;

/**
 * @ORM\ManyToMany(targetEntity="Pso\LogBundle\Entity\User", cascade= 
                  {"persist", "remove"})
 */
private $users;

 public function __construct() {
    $this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
}

当我现在尝试使用命令

生成setter和getter时
app/console doctrine:generate:entities ProjectBundle/Entity/Mandator

app/console doctrine:generate:entities ProjectBundle/Entity/Project

我收到错误

  

[RuntimeException的]     命名空间“ProjectBundle \ Entity \ Mandator”不包含任何映射的     实体。

我在没有想法的情况下阅读了几个主题,例如topic 1topic2topic 3),我的错误可能在哪里。

1 个答案:

答案 0 :(得分:0)

看起来您忘记了命名空间'Pso'的根部分。

你必须执行:

app/console doctrine:generate:entities Pso/ProjectBundle/Entity/Mandator