没有为实体指定标识符/主键 (...) 每个实体都必须具有标识符/主键 [英] No identifier/primary key specified for Entity (...) Every Entity must have and identifier/primary key

查看:38
本文介绍了没有为实体指定标识符/主键 (...) 每个实体都必须具有标识符/主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Peticion 实体,但由于出现以下错误而缺少某些内容:

I have Peticion entity but something is missing because appears the following error:

No identifier/primary key specified for Entity (...) Every Entity must have and identifier/primary key

这是实体代码:

<?php

namespace ProjectUsuarioBundleEntity;

use DoctrineORMMapping as ORM;

/**
 * Peticion
 *
 * @ORMTable(name="peticion")
 * @ORMEntity
 */
class Peticion
{
    /**
     *
     * @ORMId
     * @ORMManyToMany(targetEntity="ProjectUsuarioBundleEntityUsuario", inversedBy="usuNick2")
     * @ORMJoinTable(name="USUARIO",
     *      joinColumns={@ORMJoinColumn(name="USU_NICK_1", referencedColumnName="USU_NICK")},
     *      inverseJoinColumns={@ORMJoinColumn(name="USU_NICK_2", referencedColumnName="USU_NICK")}
     *      )
     */
    private $usuNick1;

    /**
     *
     * @ORMId
     * @ORMManyToMany(targetEntity="ProjectUsuarioBundleEntityUsuario", mappedBy="usuNick1"))
     */
    private $usuNick2;

    /**
     * @var DateTime
     *
     * @ORMColumn(name="PET_FECHA", type="date", nullable=false)
     */
    private $fecha;

推荐答案

你需要指定id字段并移除其他@ORMId注解.标识符/主键学说文档.

You need to specify id field and remove other @ORMId annotations. Identifiers / Primary Keys at doctrine documentation.

每个实体类都需要一个标识符/主键.您指定用作带有@Id 标记注释的标识符的字段.

Every entity class needs an identifier/primary key. You designate the field that serves as the identifier with the @Id marker annotation.

/**
 * @ORMId
 * @ORMColumn(type="integer")
 * @ORMGeneratedValue(strategy="AUTO")
 */
protected $id;

这篇关于没有为实体指定标识符/主键 (...) 每个实体都必须具有标识符/主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆