需要帮助在Doctrine 2 xml Mapping File中查找错误

时间:2012-07-18 22:10:58

标签: php xml doctrine-orm

我是Doctrine 2的新手,所以我使用docs.doctrine-project.org上的文档作为模板让我入门。我已经生成了我需要的所有文件(我想),现在我正在尝试运行命令

doctrine orm:schema-tool:create

但是学说正在吐痰

[Doctrine\ORM\Mapping\MappingException]                                                          
Invalid mapping file 'QueryRequest.dcm.xml' for class 'QueryRequest'.

这是我的 QueryRequest.dcm.xml (我特别依赖于来自these docs的学说示例来生成文件):

<?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://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">

    <entity name="RequestMetadata" table="request_metadata">
        <id name="id" type="bigint">
            <generator strategy="AUTO" />
        </id>

        <field name="snapshot" column="snapshot" type="smallint" nullable="true" />
        <field name="custID" column="cust_id" type="string" length="8" />
        <field name="ipAddress" column="ip_addr" type="string" length="15" />
        <field name="query" column="query" type="string" length="500" />
        <field name="createdOn" column="created_on" type="datetime" />

        <one-to-many field="httpRequestResponses" target-entity="HttpRequestResponse" mapped-by="queryRequest">
            <cascade>
                <cascade-persist />
            </cascade>
            <order-by>
                <order-by-field name="createdOn" direction="DESC" />
            </order-by>
        </one-to-many>
        <one-to-many field="queryResults" target-entity="QueryResults" mapped-by="queryRequest">
            <cascade>
                <cascade-persist />
            </cascade>
        </one-to-many>
    </entity>
</doctrine-mapping>

这是 QueryRequest.php

class QueryRequest {
    protected $id;
    protected $snapshot;
    protected $custID;
    protected $ipAddress;
    protected $query;
    protected $createdOn;

    protected $httpRequestResponses = null;
    protected $queryResults = null;


    public function __construct() {
        $this->setCreatedOn(new DateTime("now"));
        $this->httpRequestResponses = new ArrayCollection();
        $this->queryResults = new ArrayCollection();
    }
    public function getID() {
        return $this->id;
    }
    public function getSnapshot() {
        return $this->snapshot;
    }
    public function setSnapshot($snapshot) {
        $this->snapshot = $snapshot;
    }
    public function getCustID() {
        return $this->custID;
    }
    public function setCustID($id) {
        $this->custID = $id;
    }
    public function getIpAddress() {
        return $this->ipAddress;
    }
    public function setIpAddress($ip) {
        $this->ipAddress = $ip;
    }
    public function getQuery() {
        return $this->query;
    }
    public function setQuery($query) {
        $this->query = $query;
    }
    public function getCreatedOn() {
        return $this->createdOn;
    }
    public function setCreatedOn($createdOn) {
        $this->createdOn = $createdOn;
    }
}

由于我是新手,因此无法发现问题 - 实际上我甚至不确定问题是否与xml文件有关。有谁能帮我发现问题?

1 个答案:

答案 0 :(得分:5)

我弄清楚了:实体名称不正确。它应该像这样匹配类名:

<entity name="QueryRequest" table="request_metadata">

我更改了类名并错过了对xml映射文件的更新