2013-08-10 20 views
8

ho Peticion entità, ma manca qualcosa perché appare il seguente errore:No identificatore/chiave primaria specificata per entità (...) le imprese devono avere e identificatore/chiave primaria

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

Questo è il soggetto codice:

<?php 

namespace Project\UsuarioBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Peticion 
* 
* @ORM\Table(name="peticion") 
* @ORM\Entity 
*/ 
class Peticion 
{ 
    /** 
    * 
    * @ORM\Id 
    * @ORM\ManyToMany(targetEntity="Project\UsuarioBundle\Entity\Usuario", inversedBy="usuNick2") 
    * @ORM\JoinTable(name="USUARIO", 
    *  joinColumns={@ORM\JoinColumn(name="USU_NICK_1", referencedColumnName="USU_NICK")}, 
    *  inverseJoinColumns={@ORM\JoinColumn(name="USU_NICK_2", referencedColumnName="USU_NICK")} 
    *  ) 
    */ 
    private $usuNick1; 

    /** 
    * 
    * @ORM\Id 
    * @ORM\ManyToMany(targetEntity="Project\UsuarioBundle\Entity\Usuario", mappedBy="usuNick1")) 
    */ 
    private $usuNick2; 

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

risposta

15

È necessario specificare id campo e rimuovere altri @ORM\Id annotazioni. Identifiers/Primary Keys alla documentazione di doctrine.

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

/** 
* @ORM\Id 
* @ORM\Column(type="integer") 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 
+3

Questo non è corretto, Doctrine dovrebbe funzionare con ID composto (più ID) e la variabile non deve essere '$ id' – Ryall

0

Nel mio caso, quello che è successo è stato questo:

ho creare il file di entità, e metterlo nella directory entità, con lo schema del database.

Ma ecco la cosa, ho anche creato un file YML creato per l'entità e lo metto in Risorse/config/doctrine, senza uno schema. Symfony stava cercando lo schema all'interno di YML. Una volta rimosso il file YML, lo schema nel mio file di entità funzionava perfettamente.

Problemi correlati