Orm Symfony2映射到一个多个多个单体
我正在使用symfony2开发一个应用程序,并使用orm.yml文件将实体映射到数据库中。当试图为共享onetomany关系的两个实体(Anotatzea.php和Dokumentua.php)创建数据库表时,就会出现问题。当运行Orm Symfony2映射到一个多个多个单体,orm,doctrine,symfony,mapping,Orm,Doctrine,Symfony,Mapping,我正在使用symfony2开发一个应用程序,并使用orm.yml文件将实体映射到数据库中。当试图为共享onetomany关系的两个实体(Anotatzea.php和Dokumentua.php)创建数据库表时,就会出现问题。当运行php应用程序/控制台条令:schema:update--force时,它会显示下一个错误 [RuntimeException]
php应用程序/控制台条令:schema:update--force时,它会显示下一个错误
[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
}
}
第二个实体文件中的命名空间名称错误
替换:
namespace Anotatzailea\AnotatzaileaBundle\Anotatzea;
与:
namespace Anotatzailea\AnotatzaileaBundle\Entity;
namespace Anotatzailea\AnotatzaileaBundle\Entity;