MappingException:找不到目标实体

时间:2014-07-01 14:27:00

标签: php symfony doctrine-orm doctrine

我正在映射一个n:m的关系,我按照以下方式进行:

设备\ DeviceBundle \实体\ DriverHasDevice.php

namespace Device\DeviceBundle\Entity;

use Driver\DriverBundle\Entity\Driver;
use Device\DeviceBundle\Entity\Device;

class DriverHasDevice
{

    protected $driver;
    protected $device;

    public function setDriver(Driver $driver)
    {
        $this->driver = $driver;
    }

    public function getDriver()
    {
        return $this->driver;
    }

    public function setDevice(Device $device)
    {
        $this->device = $device;
    }

    public function getDevice()
    {
        return $this->device;
    }

}

设备\ DeviceBundle \资源\配置\教义\ DriverHasDevice.orm.xml

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                        http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Device\DeviceBundle\Entity\DriverHasDevice" table="driver_has_device">
        <id name="driver" association-key="true" />
        <id name="device" association-key="true" />

        <many-to-one field="driver" target-entity="Driver\DriverBundle\Entity\Driver" />
        <many-to-one field="device" target-entity="Device\DeviceBundle\Entity\Device" />
    </entity>
</doctrine-mapping>

驱动程序\ DriverBundle \实体\ Driver.php

namespace TaxiBooking\Driver\DriverBundle\Entity;


class Driver
{
    protected $id;

    protected $name;

    protected $status;


    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->firstname;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($status)
    {
        $this->status = $status;
    }
}

驱动程序\ DriverBundle \资源\配置\教义\ Driver.orm.xml

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Driver\DriverBundle\Entity\Driver" table="driver"
            repository-class="Driver\DriverBundle\Entity\Driver">
        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>
        <field name="name" type="string" column="name" length="50" precision="0" scale="0" nullable="true"/>
        <field name="status" type="integer" column="status" length="1" precision="0" scale="0" nullable="true"/>
        <gedmo:soft-deleteable field-name="deletedAt" time-aware="false"/>
    </entity>
</doctrine-mapping>

现在我正在尝试从Symfony2 shell验证运行命令Symfony > doctrine:schema:validate的架构,我收到此错误:

  

[Doctrine \ ORM \ Mapping \ MappingException]目标实体   无法找到Driver \ DriverBundle \ Entity \ Driver   “设备\ DeviceBundle \实体\ DriverHasDevice#驾驶。

我的映射中的问题在哪里?我看不出来 提前问候

1 个答案:

答案 0 :(得分:1)

您正在寻找错误的命名空间。 您的驱动程序实体具有 TaxiBooking \ Driver \ DriverBundle \ Entity 命名空间。

更改驱动程序命名空间或更改对它的引用。