I've migrated from symfony 3.4 to 4.4 moved from using bundles to /src I'm having an issue with the Entity with this error
Uncaught PHP Exception Doctrine\ORM\Mapping\MappingException: "Class
"App\Entity\Regions" is not a valid entity or mapped super class.
my Entity looks like this. I'm wondering whether this is because it can't find the orm.xml? or something else? it was in bundle/Resources. Also the Doctrine\ORM\Mapping as ORM (say's not used) is the orm.xml correct, the link here seems to show very different schema tags https://symfony.com/doc/4.4/reference/configuration/doctrine.html
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="Regions")
*/
/**
* Regions
*/
class Regions
{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $region;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
public function getRegion()
{
return $this->region;
}
}
querying the entity
$regions = $this->getDoctrine()->getRepository(Regions::class);
$regionInfo = $regions->findOneBy(array('region' => strtolower($regionSearch)));
ORM in /src/Resources/config/doctrine
<?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 https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity repository- name="App\Entity\Regions">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="region" type="string" column="region" length="40" nullable="true"/>
</entity>
</doctrine-mapping>
CodePudding user response:
Your annotations should be set right above the class declaration:
/**
* Regions
* @ORM\Entity
* @ORM\Table(name="Regions")
*/
class Regions
With your current file, only the first docblock is read and as it is missing the @ORM\Entity
annotation, Doctrine considers it isn't a valid entity class.