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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With