2012-03-12 134 views
0

我正在开发一个应用程序,使用symfony2并使用orm.yml文件将实体映射到数据库中。尝试为两个共享onomanomany关系的实体(Anotatzea.php和Dokumentua.php)创建数据库表时出现问题。当运行php app/console doctrine:schema:update --force它显示了一个错误Symfony2映射onetomany manytone

[RuntimeException]                                                                   
    The autoloader expected class "Anotatzailea\AnotatzaileaBundle\Entity\Anotatzea" to be defined in file "/var/www/Symfony/app/../src/Anotatzailea/AnotatzaileaBundle/Entity/Anotatzea.php". The file was found but the class was not in it, the class name or namespace probably has a typo. 

的实体有以下代码:

<?php 

namespace Anotatzailea\AnotatzaileaBundle\Entity; 

use Symfony\Component\Validator\Mapping\ClassMetadata; 
use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\ORM\Mapping as ORM; 

/** 
* Anotatzailea\AnotatzaileaBundle\Entity\Dokumentua 
* 
* @ORM\Table(name="Dokumentua") 
* @ORM\Entity 
*/ 
class Dokumentua 
{ 
    /** 
    * @var integer $DokId 
    * 
    * @ORM\Column(name="DokId", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $DokId; 

    /** 
    * @var string $Izenburua 
    * 
    * @ORM\Column(name="Izenburua", type="string", length=30) 
    */ 
    private $Izenburua; 

    /** 
    * @var string $Egilea 
    * 
    * @ORM\Column(name="Egilea", type="string", length=40) 
    */ 
    private $Egilea; 

    /** 
    * @var date $ErregistroData 
    * 
    * @ORM\Column(name="ErregistroData", type="date") 
    */ 
    private $ErregistroData; 

    /** 
    * @var boolean $DokEgoera 
    * 
    * @ORM\Column(name="DokEgoera", type="boolean") 
    */ 
    private $DokEgoera; 

    /** 
    * @ORM\OneToMany(targetEntity="Anotatzea", mappedBy="Dokumentua") 
    */ 
    protected $Anotatzeak; 

    /** 
    * Get DokId 
    * 
    * @return integer 
    */ 
    public function getDokId() 
    { 
     return $this->DokId; 
    } 

    /** 
    * Set Izenburua 
    * 
    * @param string $izenburua 
    */ 
    public function setIzenburua($izenburua) 
    { 
     $this->Izenburua = $izenburua; 
    } 

    /** 
    * Get Izenburua 
    * 
    * @return string 
    */ 
    public function getIzenburua() 
    { 
     return $this->Izenburua; 
    } 

    /** 
    * Set Egilea 
    * 
    * @param string $egilea 
    */ 
    public function setEgilea($egilea) 
    { 
     $this->Egilea = $egilea; 
    } 

    /** 
    * Get Egilea 
    * 
    * @return string 
    */ 
    public function getEgilea() 
    { 
     return $this->Egilea; 
    } 

    /** 
    * Set ErregistroData 
    * 
    * @param date $erregistroData 
    */ 
    public function setErregistroData($erregistroData) 
    { 
     $this->ErregistroData = $erregistroData; 
    } 

    /** 
    * Get ErregistroData 
    * 
    * @return date 
    */ 
    public function getErregistroData() 
    { 
     return $this->ErregistroData; 
    } 

    /** 
    * Set DokEgoera 
    * 
    * @param boolean $dokEgoera 
    */ 
    public function setDokEgoera($dokEgoera) 
    { 
     $this->DokEgoera = $dokEgoera; 
    } 

    /** 
    * Get DokEgoera 
    * 
    * @return boolean 
    */ 
    public function getDokEgoera() 
    { 
     return $this->DokEgoera; 
    } 

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

<?php 

namespace Anotatzailea\AnotatzaileaBundle\Anotatzea; 

use Symfony\Component\Validator\Mapping\ClassMetadata; 
use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\ORM\Mapping as ORM; 

/** 
* Anotatzailea\AnotatzaileaBundle\Entity\Anotatzea 
* 
* @ORM\Table(name="Anotatzea") 
* @ORM\Entity 
* @ORM\HasLifecycleCallbacks 
*/ 
class Anotatzea 
{ 
    /** 
    * @var integer $AnotId 
    * 
    * @ORM\Column(name="AnotId", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $AnotId; 

    /** 
    * @ORM\ManyToOne(targetEntity="Dokumentua", inversedBy="Anotatzeak") 
    * @ORM\JoinColumn(name="DokId", referencedColumnName="DokId") 
    */ 
    protected $Dokumentua; 

    /** 
    * Get AnotId 
    * 
    * @return integer 
    */ 
    public function getAnotId() 
    { 
     return $this->AnotId; 
    } 

    /** 
    * Set Dokumentua 
    * 
    * @param Anotatzailea\AnotatzaileaBundle\Entity\Dokumentua $dokumentua 
    */ 
    public function setDokumentua(\Anotatzailea\AnotatzaileaBundle\Entity\Dokumentua $dokumentua) 
    { 
     $this->Dokumentua = $dokumentua; 
    } 

    /** 
    * Get Dokumentua 
    * 
    * @return Anotatzailea\AnotatzaileaBundle\Entity\Dokumentua 
    */ 
    public function getDokumentua() 
    { 
     return $this->Dokumentua; 
    } 
    /** 
    * @ORM\prePersist 
    */ 
    public function setUpdatedValue() 
    { 
     // Add your code here 
    } 
} 

而且orm.yml文件:

Anotatzailea\AnotatzaileaBundle\Entity\Dokumentua: 
    type: entity 
    table: Dokumentua 
    fields: 
    DokId: 
     type: integer 
     id: true 
     precision: 0 
     scale: 0 
     unique: false 
     nullable: false 
     generator: 
     strategy: IDENTITY 
    Izenburua: 
     type: string 
     length: 30 
     precision: 0 
     scale: 0 
     unique: false 
     nullable: false 
    Egilea: 
     type: string 
     length: 40 
     precision: 0 
     scale: 0 
     unique: false 
     nullable: false 
    ErregistroData: 
     type: date 
     precision: 0 
     scale: 0 
     unique: false 
     nullable: false 
    DokEgoera: 
     type: boolean 
     precision: 0 
     scale: 0 
     unique: false 
     nullable: false 
    OneToMany: 
    Anotatzeak: 
     targetEntity: Anotatzailea\AnotatzaileaBundle\Entity\Anotatzea 
     cascade: { } 
     mappedBy: Dokumentua 
     inversedBy: null 
     orphanRemoval: false 
     cascade: ["persist", "merge","remove"] 
     orderBy: null 
    lifecycleCallbacks: { } 

Anotatzailea\AnotatzaileaBundle\Entity\Anotatzea: 
    type: entity 
    table: Anotatzea 
    fields: 
    AnotId: 
     type: integer 
     id: true 
     precision: 0 
     scale: 0 
     unique: false 
     nullable: false 
     generator: 
     strategy: IDENTITY 
    manyToOne: 
    Dokumentua: 
     targetEntity: Anotatzailea\AnotatzaileaBundle\Entity\Dokumentua 
     cascade: { } 
     mappedBy: null 
     inversedBy: Anotatzeak 
     joinColumns: 
     DokId: 
      referencedColumnName: DokId 
     orphanRemoval: false 
    lifecycleCallbacks: { } 

回答

2

第二实体的命名空间名称文件是错误的。

替换:

namespace Anotatzailea\AnotatzaileaBundle\Anotatzea; 

有:

namespace Anotatzailea\AnotatzaileaBundle\Entity; 
相关问题