TransWikia.com

The target-entity "some entity" cannot be found

Stack Overflow Asked by noobie-php on December 25, 2021

i am using ZF2 with doctrine i am getting this error.

The target-entity EntityUser cannot be found in ‘SubjectEntitySubject#user’.

Here is the snippet to my code.

<?php

namespace SubjectEntity;

use DoctrineORMMapping as ORM;
use ZendInputFilterInputFilter;
use ZendInputFilterFactory as InputFactory;
use ZendInputFilterInputFilterAwareInterface;
use ZendInputFilterInputFilterInterface;
/** 

* @ORMEntity

* @ORMTable(name="subject")

* @property string $subjectname

* @property int $user_id

* @property int $id

*/
 class Subject implements InputFilterAwareInterface {

  protected $inputFilter;
 /**

 * @ORMId

 * @ORMColumn(type="integer");

 * @ORMGeneratedValue(strategy="AUTO")

 */
protected $id;
/**

 * @ORMColumn(type="string")

 */
protected $subjectname;

/**
 * @ORMManyToOne(targetEntity="EntityUser", inversedBy="subjects")
 * @var User|null
 */
private $user;

/** @return User|null */
public function getUser() {
    return $this->user;
}

/** @param User $user */
public function setUser(User $user) {
    if($user === null || $user instanceof User) {
        $this->user = $user;
    } else {
        throw new InvalidArgumentException('$user must be instance of EntityUser or null!');
    }
}}

and then my “User” entity

namespace SubjectEntity;

use DoctrineORMMapping as ORM;
use ZendInputFilterInputFilter;
use ZendInputFilterFactory as InputFactory;
use ZendInputFilterInputFilterAwareInterface;
use ZendInputFilterInputFilterInterface;

/*
* @ORMEntity

* @ORMTable(name="users")

* @property string $username

* @property string $password

* @property int $id

*/
class User implements InputFilterAwareInterface {

 protected $_username;
 protected $_password;

 /**
 * @ORMOneToMany(targetEntity="EntitySubject", mappedBy="user")
 * @var Collection
 */
private $subjects;

/** @ORMId() @ORMColumn(type="integer") @ORMGeneratedValue(strategy="AUTO") @var   int */
protected $_id;

public function __get($property) {

    return $this->$property;
}

public function __set($property, $value) {

    $this->$property = $value;
}

//Getters and setters

/** @return Collection */
public function getSubjects() {
    return $this->comments;
}

/** @param Comment $comment */
public function addSubject(Subject $comment) {
    $this->comments->add($comment);
    $comment->setUser($this);
}

}

2 Answers

In our case, the file name was not the same as the class name: it was just a typo.

Answered by mariusa on December 25, 2021

Your entity declaration is incorrect:

 * @ORMManyToOne(targetEntity="EntityUser", inversedBy="subjects")

This should be either this:

 * @ORMManyToOne(targetEntity="SubjectEntityUser", inversedBy="subjects")

Or, since the two classes share the same namespace, you can also use this:

 * @ORMManyToOne(targetEntity="User", inversedBy="subjects")

The targetEntity has to be the fully qualified class name (FQCN), except if referring to a class in the same namespace, in which case the short name may be used (as per the last example above).

Answered by leftclickben on December 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP