2012-05-24 24 views
5

Quali sono le possibili cause di EntityNotFoundException durante l'accesso alle proprietà della classe proxy in doctrine 2? In ogni caso, il seguente è la struttura i miei entita:EntityNotFoundException in doctrine 2 classe proxy

/** 
* @ORM\Table(name="comments") 
* 
* @ORM\InheritanceType("JOINED") 
* @ORM\DiscriminatorColumn(name="comment_type", type="smallint") 
* @ORM\DiscriminatorMap({ 
* 1 = "VisitorComment", 
* 2 = "MemberComment" 
* }) 
*/ 
class Comment 
{ 
    //with common properties of its subclasses 
} 

sottoclassi sono i seguenti:

/** 
* @ORM\Table(name="member_comments") 
*/ 
class MemberComment extends Comment 
{ 
    /** 
    * owning side 
    * 
    * @var Member $author 
    * 
    * @ORM\ManyToOne(targetEntity="Member") 
    * @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false) 
    */ 
    private $author; 

    /** 
    * Set author 
    * 
    * @param Member $author 
    */ 
    public function setAuthor($author) 
    { 
     $this->author = $author; 
    } 

    /** 
    * Get author 
    * 
    * @return Member 
    */ 
    public function getAuthor() 
    { 
     return $this->author; 
    } 
} 


/** 
* @ORM\Table(name="visitor_comments") 
*/ 
class VisitorComment extends Comment 
{ 
    /** 
    * owning side 
    * 
    * @var Visitor $author 
    * 
    * @ORM\ManyToOne(targetEntity="Visitor") 
    * @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false) 
    */ 
    private $author; 

    /** 
    * Set author 
    * 
    * @param string $author 
    */ 
    public function setAuthor($author) 
    { 
     $this->author = $author; 
    } 

    /** 
    * Get author 
    * 
    * @return Visitor 
    */ 
    public function getAuthor() 
    { 
     return $this->author; 
    } 
} 

L'eccezione si verifica quando chiamo $ comment-> getAuthor() -> getFirstName() < assumendo l'autore che è un'entità membro o visitatore ha proprietà firstName>. GetAuthor() in questo caso restituisce una classe proxy di VisitorProxy o MemberProxy.

Gentilmente aiutatemi. Sono ancora nuovo alla dottrina.

+3

È stata colpa mia. Dal momento che aggiungo ancora manualmente i miei dati nel database, ho erroneamente scambiato il visitatore con il commento del membro e con il commento del visitatore come autore. – Floricel

risposta

2

Come ha scoperto Floricel, ciò può essere causato da una chiave esterna non valida in una colonna che punta alla tabella a cui fa riferimento la classe Proxy.

0

@Dave Lancea ha ragione Ho cambiato un FK su non Null e poi ho iniziato a ricevere questo errore, aggiornato manualmente un record interrotto, facendo in modo che puntasse a un'entità esistente e al problema scomparso.