2012-05-24 73 views
5

而在學說2訪問代理類的屬性是什麼EntityNotFoundException可能的原因是什麼?不管怎樣,下面是我的實體的結構:EntityNotFoundException教義2代理類

/** 
* @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 
} 

子類如下:

/** 
* @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; 
    } 
} 

當我調用$ comment-> getAuthor()發生異常 - >的getFirstName()< 假設作爲會員或訪客實體的作者具有名字屬性>。在這種情況下,getAuthor()返回VisitorProxy或MemberProxy的代理類。

請幫助我。我對教義仍然陌生。

+3

這是我的錯。因爲我還是手動添加數據庫中我的數據,我錯誤地交換訪問者成員的評論和成員向顧客作爲作者的評論。 – Floricel

回答

2

由於Floricel發現,這可以通過在列的分表的代理類引用無效外鍵造成的。

0

@戴夫蘭石是對的,我改變了FK,以不爲空,然後開始收到此錯誤,手動更新一個破紀錄,使其指向一個現有實體和問題走了。