Doctrine Is not a valid entity or mapped super class

寵の児 提交于 2021-01-28 16:32:14

问题


i have a problem with doctrine and i getting this error from auto generated entity file "Class "Users" is not a valid entity or mapped super class.". File and comments inside looks like fine i dont understund why or i something miss? Some piece of code

<?php

use Doctrine\ORM\Mapping as ORM;

/**
* Users
*
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"username"})})
* @ORM\Entity
*/

class Users
{
   /**
  * @var integer
  *
  * @ORM\Column(name="userid", type="integer", nullable=false)
  * @ORM\Id
  * @ORM\GeneratedValue(strategy="IDENTITY")
  */

  private $userid;

/**
 * @var string
 *
 * @ORM\Column(name="username", type="string", length=100, nullable=false)
 */
  private $username;

回答1:


Doctrine 2 annotation mapping might have been configured to negate the need for the @ORM prefix.

I would try replacing @ORM\ with @. For example @Entity




回答2:


As far as i recall, these errors happen when doctrine cant find the entity, double check the namespace, by default the entity folder in symfony is "Entity" (Uppercase!). Also check the config files if auto_mapping is set to true.




回答3:


for me this problem was solved after adding following namespace

use Doctrine\Common\Annotations\AnnotationReader;

in my doctrine.php



来源:https://stackoverflow.com/questions/37205609/doctrine-is-not-a-valid-entity-or-mapped-super-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!