【问题标题】:The annotation @Doctrine\ORM\Mapping in class xx does not exist, or cannot be loadedxx类中的注解@Doctrine\ORM\Mapping不存在,或者无法加载
【发布时间】:2014-11-07 14:15:44
【问题描述】:

在执行php app/console doctrine:generate:entities etBundle:Users 时收到此错误消息:

[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Doctrine\ORM\Mapping" in class Ampisoft\Bundle\etrackBundle\Entity\Users does not exist, or could not be auto-loaded.

我的实体类如下:

namespace Ampisoft\Bundle\etrackBundle\Entity;


 use Doctrine\ORM\Mapping as ORM;

 /**
 * @ORM/Entity
 * @ORM/Table(name="users")
 */
class Users
{
/**
 * @ORM/Column(type="integer")
 * @ORM/ID
 * @ORM/GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=25, unique=true)
 */
protected $username;

/**
 * @ORM\Column(type="string", length=64)
 */
protected $password;


/**
 * @ORM\Column(name="is_active", type="boolean")
 */
private $isActive;

/**
 * @ORM\Column(type="string", length=60, unique=true)
 */
protected $email;

/**
 * @ORM\Column(type="datetime")
 */
protected $lastLogged;
}

我查看了 SO 并找到了与类似问题相匹配但与属性相关的解决方案,以及与 zend 相关但与 symfony2 中的实际类声明无关的解决方案。

我已经使用 composer 安装和更新了所有供应商软件包。

谁能指点我正确的方向?

我是 symfony 的新手。非常感谢

【问题讨论】:

  • 嗯,我认为您需要将正斜杠替换为反斜杠:@ORM/Entity 替换为 @ORM\Entity。不知道这是否会有所帮助,但尝试一下也无妨……;)

标签: php symfony doctrine-orm doctrine


【解决方案1】:

如果您在注释名称中使用正斜杠 (/) 而不是反斜杠 (\),则会收到此错误。也就是说,如果你这样做,就会出现错误:

/**
 * @ORM/Entity
 */

而不是正确的:

/**
 * @ORM\Entity
 */

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-26
    相关资源
    最近更新 更多