在doctrine 2中没有为Entity指定标识符/主键

Tay*_*bab 3 entity doctrine-orm zend-framework2

我正在使用Zend 2 Framework,我正在尝试使用Doctrine 2获取数据.

但是,实体文件中会出现以下错误.

学说\ ORM \制图\ MappingException

没有为实体"Acl\Entity\Permission"指定标识符/主键.每个实体必须具有标识符/主键.

如何指定主键?

我使用以下代码.

/**
 * User Permissions
 *
 * @ORM\Entity
 * @ORM\Table(name="acl_permissions")
 * @property int $id
 * @property int $role_id
 * @property int $resource_id
 * @property string $action
 */
class Permission
{
    /**
     * @ORM\Column(type="integer")
     */
    public $id;

    /**
     * @ORM\Column(type="integer")
     * @ORM\OneToOne(targetEntity="Role")
     * @ORM\JoinColumn(name="role_id", referencedColumnName="id")
     */
    public $role;

    /**
     * @ORM\Column(type="integer")
     * @ORM\OneToOne(targetEntity="Resource")
     * @ORM\JoinColumn(name="resource_id", referencedColumnName="id")
     */
    public $resource;

    /**
     * @ORM\Column(type="string")
     */
    public $action;

    public function getRole()
    {
    return $this->role;
    }

    public function getResource()
    {
    return $this->resource;
    }
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*l M 7

你检查过文档了吗?

您可以使用@ORM\Id注释定义主键.如果值是自动生成的(例如,如果使用auto_increment),则还需要设置@ORM\GeneratedValue(strategy="IDENTITY")注释.