Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityNotFoundException in doctrine 2 proxy class

What are the possible causes of EntityNotFoundException while accessing the proxy class properties in doctrine 2? Anyway, the following is my entities' structure:

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

subclasses are as follows:

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

The exception occurs when I call $comment->getAuthor()->getFirstName() <assuming that author which is either a Member or Visitor entity has firstName property>. The getAuthor() in this case returns a proxy class of either VisitorProxy or MemberProxy.

Kindly help me. I'm still new to doctrine.

like image 776
Floricel Avatar asked Nov 04 '22 23:11

Floricel


1 Answers

As Floricel found out, this can be caused by an invalid foreign key in a column that's points to the table that the Proxy class references.

like image 137
Dave Lancea Avatar answered Nov 15 '22 07:11

Dave Lancea