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 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多