I’m new to Doctrine 2, so I’m using the documentation on docs.doctrine-project.org as a template to get me started. I’ve generated all of the files I need (I think), and now I’m trying to run the command
doctrine orm:schema-tool:create
but doctrine is spitting back
[Doctrine\ORM\Mapping\MappingException]
Invalid mapping file 'QueryRequest.dcm.xml' for class 'QueryRequest'.
Here’s my QueryRequest.dcm.xml (I especially relied on a doctrine example from these docs to generate the file):
<?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>
Here’s 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;
}
}
Since I’m new I’m having trouble spotting the problem – in fact I don’t even know for sure if the problem is with the xml file. Can anyone help me spot the problem?
I figured it out: entity name was incorrect. It should have matched the class name like so:
I’d made a change to the class name and missed the update to the xml mapping file