I am developing an application using symfony2 and using orm.yml files for mapping the entities into the database. The problem comes when trying to create the database tables for two entities that share a onetomany relationship (Anotatzea.php and Dokumentua.php). When running php app/console doctrine:schema:update --force it shows the next error
[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.
The entities have the following code:
<?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
}
}
And the orm.yml files:
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: { }
The namespace name in the second entity file is wrong.
Replace:
with: