Symfony 2.1错误:在存储库中导入@ORM\Table

Symfony 2.1错误:在存储库中导入@ORM\Table,symfony,doctrine-orm,symfony-2.1,Symfony,Doctrine Orm,Symfony 2.1,我正在将一个应用程序从Symfony 2.0升级到Symfony 2.1,我遵循了升级文件,所有工作正常,只是在缓存:清除后,我在使用某些存储库时出错。以下是错误: [Semantical Error] The annotation "@ORM\Table" in class edasiclinic\AlertesBundle\Repository\AlertesRepository was never imported. Did you maybe forget to add a "use"

我正在将一个应用程序从Symfony 2.0升级到Symfony 2.1,我遵循了升级文件,所有工作正常,只是在
缓存:清除
后,我在使用某些存储库时出错。以下是错误:

[Semantical Error] The annotation "@ORM\Table" in class 
edasiclinic\AlertesBundle\Repository\AlertesRepository was never imported. Did you maybe
forget to add a "use" statement for this annotation?
这是一个例子,我在其他存储库中遇到这个错误。我不明白如果我不在存储库文件中使用注释,为什么我必须在存储库文件中导入
@ORM\Table

另外,如果我等待约10秒,然后刷新浏览器,它会工作

编辑

这是实体:

<?php

namespace edasiclinic\DatabaseBundle\Entity;

use Doctrine\ORM\Mapping as ORM;


/**
 * edasiclinic\DatabaseBundle\Entity\Alertes
 *
 * @ORM\Table(name="alertes")
 * @ORM\Entity(repositoryClass="edasiclinic\AlertesBundle\Repository\AlertesRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Alertes
{
    /**
     * @var integer $id
     *
     * @ORM\Id
     * @ORM\Column(name="idAlerta", type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    ...
}

看起来您忘记添加
use
语句了

<?php

namespace Acme\MyBundle\Entity;

// Remember to include this use statement
use Doctrine\ORM\Mapping as ORM;

/**
 * My Entity
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Acme\MyBundle\Entity\MyEntityRepository")
 */
class MyEntity
{
}

我今天也遇到了同样的问题。在谷歌搜索之后,解决方案显然是在存储库类定义之前包含一个注释块

就你而言:

/** * AlertesRepository */ class AlertesRepository extends EntityRepository { ... } /** *警报存储 */ 类AlertesRepository扩展了EntityRepository { ... }
如果没有该注释块,您将收到关于“@ORM\Table”的无意义错误。然而,另一个Symfony/Doctrine奇怪之处>

对我来说,它只出现在某些PHP版本中,解决方案是将Repository类放在实体类文件夹上方的文件夹中,这在5.3.8之前的版本中是一个PHP错误。从:


如果无法升级到PHP版本>=5.3.8,请参阅以了解更多详细信息和可能的解决方法。

顶部是否有
使用条令\ORM\Mapping as ORM
?在实体中(使用此存储库类)是,但是在存储库中没有。我没有在任何存储库中导入
orm\mapping
。如果您使用
@orm
注释,那么,据我所知,您应该导入映射jobby。我在
内核的侦听器中使用它。request
,可能在它应该被调用之前就被调用了?是的,这很有效!几个月前,我通过在repo类中添加ORM\Mapping解决了这个问题,但我更喜欢这个解决方案。我仍然不知道为什么会出现这样的错误:S /** * AlertesRepository */ class AlertesRepository extends EntityRepository { ... }
$this->addRecommendation(
    version_compare($installedPhpVersion, '5.3.8', '>='),
    'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156',
    'Install PHP 5.3.8 or newer if your project uses annotations.'
);