dslfjrmz70457 2014-07-01 14:26
浏览 63
已采纳

MappingException:找不到目标实体

I'm mapping a n:m relationship and I do it as follow:

Device\DeviceBundle\Entity\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;
    }

}

Device\DeviceBundle\Resources\config\doctrine\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>

Driver\DriverBundle\Entity\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;
    }
}

Driver\DriverBundle\Resources\config\doctrine\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>

Now I'm trying to validate the schema running the command Symfony > doctrine:schema:validate from Symfony2 shell and I get this error:

[Doctrine\ORM\Mapping\MappingException] The target-entity Driver\DriverBundle\Entity\Driver cannot be found in 'Device\DeviceBundle\Entity\DriverHasDevice#driver'.

Where is the problem in my mapping? I can't see it Regards in advance

  • 写回答

1条回答 默认 最新

  • doudai8083 2014-07-01 15:05
    关注

    Your looking for the wrong namespace. Your Driver Entity has TaxiBooking\Driver\DriverBundle\Entity namespace.

    Change the Driver namespace or change the references to it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值