0

每当我尝试使用 EntityManager 查找或查询具有关联的对象时,我都会收到上述错误。我绝对找不到任何无法找到目标实体的押韵或原因。下面是一些示例代码和错误。我没有编辑具体的名字,因为这可能是一个命名空间问题。

错误:

[06-Jun-2013 17:35:30 America/Boise] exception 'Doctrine\ORM\Mapping\MappingException' with message 'The target-entity SGN\Models\BetterButtonNonprofit cannot be found in 'SGN\Models\Nonprofit#betterButtonNonprofit'.' in /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:428
Stack trace:
#0 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php(905): Doctrine\ORM\Mapping\MappingException::invalidTargetEntityClass('SGN\Models\Bett...', 'SGN\Models\Nonp...', 'betterButtonNon...')
#1 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(189): Doctrine\ORM\Mapping\ClassMetadataInfo->validateAssocations()
#2 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(171): Doctrine\ORM\Mapping\ClassMetadataFactory->validateRuntimeMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL)
#3 /var/www-staging4/html/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(302): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array)
#4 /var/www-staging4/html/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(205): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('SGN\Models\Nonp...')
#5 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(268): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('SGN\Models\Nonp...')
#6 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2517): Doctrine\ORM\EntityManager->getClassMetadata('SGN\Models\Nonp...')
#7 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php(246): Doctrine\ORM\UnitOfWork->createEntity('SGN\Models\Proj...', Array, Array)
#8 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php(479): Doctrine\ORM\Internal\Hydration\ObjectHydrator->_getEntity(Array, 'p')
#9 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php(150): Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData(Array, Array, Array)
#10 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php(111): Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData()
#11 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(751): Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(Object(Doctrine\DBAL\Driver\PDOStatement), Object(Doctrine\ORM\Query\ResultSetMapping), Array)
#12 /var/www-staging4/html/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(610): Doctrine\ORM\AbstractQuery->execute(NULL, NULL)
#13 /var/www-staging4/html/non-profit/index.php(355): Doctrine\ORM\AbstractQuery->getSingleResult()
#14 /var/www-staging4/html/support(46): include('/var/www-stagin...')
#15 {main}

模型/BetterButtonNonprofit.php:

<?php

namespace SGN\Models;

/**
 * @Entity
 * @Table(name="betterbutton_nonprofit")
 **/
class BetterButtonNonprofit
{
    /**
     * @Column(type="string", name="uid", nullable=false, unique=true)
     **/
    protected $uid;

    /**
     * @Column(type="string", name="ein_or_cfid", nullable=true)
     **/
    protected $einOrCfid;

    /**
     * @Column(type="string", name="key", nullable=true)
     **/
    protected $nonprofitKey;

    /**
     * @Id
     * @GeneratedValue
     * @Column(type="integer", name="invoice_key", nullable=false)
     **/
    protected $invoiceKey;

    /**
     * @Column(type="string", name="name", nullable=false)
     **/
    protected $nonprofitName;

    /**
     * @Column(type="string", name="small_name", nullable=true)
     **/
    protected $smallName;

    /**
     * @Column(type="string", name="twitter_handle", nullable=true)
     **/
    protected $twitterHandle;

    /**
     * @Column(type="string", name="address", nullable=true)
     **/
    protected $address;

    /**
     * @Column(type="string", name="address2", nullable=true)
     **/
    protected $address2;

    /**
     * @Column(type="string", name="city", nullable=true)
     **/
    protected $city;

    /**
     * @Column(type="string", name="state", nullable=true)
     **/
    protected $state;

    /**
     * @Column(type="string", name="zip", nullable=true)
     **/
    protected $zip;

    /**
     * @Column(type="datetime", name="created", nullable=true)
     **/
    protected $created;

    /**
     * @Column(type="datetime", name="last_updated", nullable=false)
     **/
    protected $lastUpdated;

    /**
     * @Column(type="boolean", name="restrict_to_host", nullable=false)
     **/
    protected $restrictToHost;

    /**
     * @Column(type="text", name="host", nullable=true)
     **/
    protected $host;

    /**
     * @Column(type="text", name="host_2", nullable=true)
     **/
    protected $host2;

    /**
     * @Column(type="text", name="host_3", nullable=true)
     **/
    protected $host3;

    /**
     * @Column(type="string", name="host_image", nullable=true)
     **/
    protected $hostImage;

    /**
     * @Column(type="string", name="host_image_2", nullable=true)
     **/
    protected $hostImage2;

    /**
     * @Column(type="string", name="host_image_3", nullable=true)
     **/
    protected $hostImage3;

    /**
     * @Column(type="boolean", name="text_to_give", nullable=false)
     **/
    protected $textToGive;

    /**
     * @Column(type="boolean", name="aggressive_pushdown_mode", nullable=false)
     **/
    protected $aggressivePushdownMode;

    /**
     * @Column(type="string", name="button_type", nullable=false)
     **/
    protected $buttonType;

    /**
     * @Column(type="boolean", name="enable_notifications", nullable=false)
     **/
    protected $enableNotifications;

    /**
     * @Column(type="boolean", name="is_disruptive", nullable=false)
     **/
    protected $isDisruptive;

    /**
     * @OneToOne(targetEntity="SGN\Models\Nonprofit", mappedBy="betterButtonNonprofit")
     **/
    protected $sgnNonprofit;

    /**
     * @OneToMany(targetEntity="SGN\Models\BetterButtonTransaction", mappedBy="betterButtonNonprofit")
     **/
    protected $betterButtonTransactions;





    public function getUID()
    {
        return $this->uid;
    }

    public function setUID($uid)
    {
        $this->uid = $uid;
    }

    public function getEinOrCfid()
    {
        return $this->einOrCfid;
    }

    public function setEinOrCfid($einOrCfid)
    {
        $this->einOrCfid = $einOrCfid;
    }

    public function getKey()
    {
        return $this->nonprofitKey;
    }

    public function setKey($nonprofitKey)
    {
        $this->nonprofitKey = $nonprofitKey;
    }

    public function getInvoiceKey()
    {
        return $this->invoiceKey;
    }

    public function getName()
    {
        return $this->nonprofitName;
    }

    public function setName($nonprofitName)
    {
        $this->nonprofitName = $nonprofitName;
    }

    public function getSmallName()
    {
        return $this->smallName;
    }

    public function setSmallName($smallName)
    {
        $this->smallName = $smallName;
    }

    public function getTwitterHandle()
    {
        return $this->twitterHandle;
    }

    public function setTwitterHandle($twitterHandle)
    {
        $this->twitterHandle = $twitterHandle;
    }

    public function getAddress()
    {
        return $this->address;
    }

    public function setAddress($address)
    {
        $this->address = $address;
    }

    public function getAddress2()
    {
        return $this->address2;
    }

    public function setAddress2($address2)
    {
        $this->address2 = $address2;
    }

    public function getCity()
    {
        return $this->city;
    }

    public function setCity($city)
    {
        $this->city = $city;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setState($state)
    {
        $this->state = $state;
    }

    public function getZip()
    {
        return $this->zip;
    }

    public function setZip($zip)
    {
        $this->zip = $zip;
    }

    public function getCreatedDate()
    {
        return $this->created;
    }

    public function setCreatedDate($created)
    {
        $this->created = $created;
    }

    public function getLastUpdated()
    {
        return $this->lastUpdated;
    }

    public function setLastUpdated($lastUpdated)
    {
        $this->lastUpdated = $lastUpdated;
    }

    public function getRestrictToHost()
    {
        return $this->restrictToHost;
    }

    public function setRestrictToHost($restrictToHost)
    {
        $this->restrictToHost = $restrictToHost;
    }

    public function getHost()
    {
        return $this->host;
    }

    public function setHost($host)
    {
        $this->host = $host;
    }

    public function getHost2()
    {
        return $this->host2;
    }

    public function setHost2($host2)
    {
        $this->host2 = $host2;
    }

    public function getHost3()
    {
        return $this->host3;
    }

    public function setHost3($host3)
    {
        $this->host3 = $host3;
    }

    public function getHostImage()
    {
        return $this->hostImage;
    }

    public function setHostImage($hostImage)
    {
        $this->hostImage = $hostImage;
    }

    public function getHostImage2()
    {
        return $this->hostImage2;
    }

    public function setHostImage2($hostImage2)
    {
        $this->hostImage2 = $hostImage2;
    }

    public function getHostImage3()
    {
        return $this->hostImage3;
    }

    public function setHostImage3($hostImage3)
    {
        $this->hostImage3 = $hostImage3;
    }

    public function getTextToGive()
    {
        return $this->textToGive;
    }

    public function setTextToGive($textToGive)
    {
        $this->textToGive = $textToGive;
    }

    public function getAggressivePushdownMode()
    {
        return $this->aggressivePushdownMode;
    }

    public function setAggressivePushdownMode($aggressivePushdownMode)
    {
        $this->aggressivePushdownMode = $aggressivePushdownMode;
    }

    public function getButtonType()
    {
        return $this->buttonType;
    }

    public function setButtonType($buttonType)
    {
        $this->buttonType = $buttonType;
    }

    public function getEnableNotifications()
    {
        return $this->enableNotifications;
    }

    public function setEnableNotifications($enableNotifications)
    {
        $this->enableNotifications = $enableNotifications;
    }

    public function getIsDisruptive()
    {
        return $this->isDisruptive;
    }

    public function setIsDisruptive($isDisruptive)
    {
        $this->isDisruptive = $isDisruptive;
    }

    public function getSGNNonprofit()
    {
        return $this->sgnNonprofit;
    }

    public function setSGNNonprofit($sgnNonprofit)
    {
        $this->sgnNonprofit = $sgnNonprofit;
    }


    public function getBetterButtonTransactions()
    {
        return $this->betterButtonTransactions;
    }


}

模特/非营利组织:

<?php

namespace SGN\Models;

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity
 * @Table(name="nonprofits")
 **/
class Nonprofit
{
    // ===================================================================== //
    // Attributes
    // ===================================================================== //

    /**
     * @Column(type="string", name="nonprofit_uid")
     **/
    protected $uid;

    /**
     * @Id
     * @GeneratedValue
     * @Column(type="integer", name="nonprofit_unique_number")
     **/
    protected $uniqueNumber;

    /**
     * @Column(type="string", name="nonprofit_status_internal", nullable=true)
     **/
    protected $internalStatus;

    /**
     * @Column(type="boolean", name="nonprofit_completed_signup")
     **/
    protected $completedSignup = false;

    /**
     * @Column(type="string", name="nonprofit_name")
     **/
    protected $nonprofitName;

    /**
     * @Column(type="string", name="nonprofit_name_short", nullable=true)
     **/
    protected $shortName;

    /**
     * @Column(type="string", name="nonprofit_firstname", nullable=true)
     **/
    protected $firstName;

    /**
     * @Column(type="string", name="nonprofit_lastname", nullable=true)
     **/
     protected $lastName;

    /**
     * @Column(type="string", name="nonprofit_contact_name", nullable=false)
     **/
     protected $contactName;

    /**
     * @Column(type="string", name="nonprofit_contact_title", nullable=false)
     **/
    protected $contactTitle;

    /**
     * @Column(type="string", name="nonprofit_address1", nullable=false)
     **/
    protected $address1;

    /**
     * @Column(type="string", name="nonprofit_address2", nullable=false)
     **/
    protected $address2;

    /**
     * @Column(type="string", name="nonprofit_city", nullable=false)
     **/
    protected $city;

    /**
     * @Column(type="string", name="nonprofit_state", nullable=false)
     **/
    protected $state;

    /**
     * @Column(type="string", name="nonprofit_zip", nullable=false)
     **/
    protected $zip;

    /**
     * @Column(type="string", name="nonprofit_phone1", nullable=false)
     **/
    protected $phone1;

    /**
     * @Column(type="string", name="nonprofit_phone2", nullable=false)
     **/
    protected $phone2;

    /**
     * @Column(type="string", name="nonprofit_phone3", nullable=false)
     **/
    protected $phone3;

    /**
     * @Column(type="string", name="nonprofit_email", nullable=false)
     **/
    protected $email;

    /**
     * @Column(type="string", name="nonprofit_501c3", nullable=true)
     **/
    protected $nonprofit501c3;

    /**
     * @Column(type="string", name="nonprofit_ein", nullable=true)
     **/
    protected $ein;

    /**
     * @Column(type="string", name="nonprofit_url", nullable=true)
     **/
    protected $url;

    /**
     * @Column(type="string", name="nonprofit_logo", nullable=true)
     **/
    protected $logo;

    /**
     * @Column(type="string", name="nonprofit_logo_type", nullable=true)
     **/
    protected $logoType;

    /**
     * @Column(type="string", name="nonprofit_video", nullable=true)
     **/
    protected $video;

    /**
     * @Column(type="string", name="nonprofit_description", nullable=true)
     **/
    protected $nonprofitDescription;

    /**
     * @Column(type="string", name="nonprofit_username", nullable=false, unique=true)
     **/
    protected $username;

    /**
     * @Column(type="string", name="nonprofit_password", nullable=false)
     **/
    protected $password;

    /**
     * @Column(type="datetime", name="nonprofit_creation", nullable=false)
     **/
    protected $creationDate;

    /**
     * @Column(type="datetime", name="nonprofit_last_updated", nullable=true)
     **/
    protected $lastUpdated;

    /**
     * @Column(type="string", name="nonprofit_status", nullable=false)
     **/
    protected $status = '1';

    /**
     * @Column(type="string", name="nonprofit_direct_giving", nullable=false)
     **/
    protected $directGiving = 'OFF';

    /**
     * @Column(type="datetime", name="nonprofit_direct_giving_added", nullable=true)
     **/
    protected $directGivingAdded;

    /**
     * @Column(type="string", name="nonprofit_facebook_share_message", nullable=true)
     **/
    protected $facebookShareMessage;

    /**
     * @Column(type="string", name="nonprofit_facebook_url", nullable=true)
     **/
    protected $facebookURL;

    /**
     * @Column(type="string", name="nonprofit_twitter_url", nullable=true)
     **/
    protected $twitterURL;


    /**
     * @OneToOne(targetEntity="BetterButtonNonprofit", inversedBy="sgnNonprofit")
     * @JoinColumn(name="nonprofit_betterbutton_uid", referencedColumnName="uid")
     **/
    protected $betterButtonNonprofit;


     /**
      * @OneToMany(targetEntity="Project", mappedBy="nonprofit")
      **/
    protected $projects;





    public function getUID()
    {
        return $this->uid;
    }

    public function setUID($uid)
    {
        $this->uid = $uid;
    }

    public function getUniqueNumber()
    {
        return $this->uniqueNumber;
    }

    public function getInternalStatus()
    {
        return $this->internalStatus;
    }

    public function setInternalStatus($internalStatus)
    {
        $this->internalStatus = $internalStatus;
    }

    public function getCompletedSignup()
    {
        return $this->completedSignup;
    }

    public function setCompletedSignup($completedSignup)
    {
        $this->completedSignup = $completedSignup;
    }

    public function getName()
    {
        return $this->nonprofitName;
    }

    public function setName($name)
    {
        $this->nonprofitName = $name;
    }

    public function getShortName()
    {
        return $this->shortName;
    }

    public function setShortName($shortName)
    {
        $this->shortName = $shortName;
    }

    public function getFirstName()
    {
        return $this->firstName;
    }

    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;
    }

    public function getLastName()
    {
        return $this->lastName;
    }

    public function setLastName($lastName)
    {
        $this->lastName = $lastName;
    }

    public function getContactName()
    {
        return $this->contactName;
    }

    public function setContactName($contactName)
    {
        $this->contactName = $contactName;
    }

    public function getContactTitle()
    {
        return $this->contactTitle;
    }

    public function setContactTitle($contactTitle)
    {
        $this->contactTitle = $contactTitle;
    }

    public function getAddress1()
    {
        return $this->address1;
    }

    public function setAddress1($address1)
    {
        $this->address1 = $address1;
    }

    public function getAddress2()
    {
        return $this->address2;
    }

    public function setAddress2($address2)
    {
        $this->address2 = $address2;
    }

    public function getAddress3()
    {
        return $this->address3;
    }

    public function setAddress3($address3)
    {
        $this->address3 = $address3;
    }

    public function getCity()
    {
        return $this->city;
    }

    public function setCity($city)
    {
        $this->city = $city;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setState($state)
    {
        $this->state = $state;
    }

    public function getZip()
    {
        return $this->zip;
    }

    public function setZip($zip)
    {
        $this->zip = $zip;
    }

    public function getPhone1()
    {
        return $this->phone1;
    }

    public function setPhone1($phone1)
    {
        $this->phone1 = $phone1;
    }

    public function getPhone2()
    {
        return $this->phone2;
    }

    public function setPhone2($phone2)
    {
        $this->phone2 = $phone2;
    }

    public function getPhone3()
    {
        return $this->phone3;
    }

    public function setPhone3($phone3)
    {
        $this->phone3 = $phone3;
    }

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }

    public function get501c3()
    {
        return $this->nonprofit501c3;
    }

    public function set501c3($nonprofit501c3)
    {
        $this->nonprofit501c3 = $nonprofit501c3;
    }

    public function getEIN()
    {
        return $this->ein;
    }

    public function setEIN($ein)
    {
        $this->ein = $ein;
    }

    public function getURL()
    {
        return $this->url;
    }

    public function setURL($url)
    {
        $this->url = $url;
    }

    public function getLogo()
    {
        return $this->logo;
    }

    public function setLogo($logo)
    {
        $this->logo = $logo;
    }

    public function getLogoType()
    {
        return $this->logoType;
    }

    public function setLogoType($logoType)
    {
        $this->logoType = $logoType;
    }

    public function getVideo()
    {
        return $this->video;
    }

    public function setVideo($video)
    {
        $this->video = $video;
    }

    public function getDescription()
    {
        return $this->nonprofitDescription;
    }

    public function setDescription($nonprofitDescription)
    {
        $this->nonprofitDescription = $nonprofitDescription;
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function setUsername($username)
    {
        $this->username = $username;
    }

    public function getPassword()
    {
        return $this->password;
    }

    public function setPassword($password)
    {
        $this->password = $password;
    }

    public function getCreationDate()
    {
        return $this->creationDate;
    }

    public function setCreationDate($creationDate)
    {
        $this->creationDate = $creationDate;
    }

    public function getLastUpdated()
    {
        return $this->lastUpdated;
    }

    public function setLastUpdated($lastUpdated)
    {
        $this->lastUpdated = $lastUpdated;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($status)
    {
        $this->status = $status;
    }

    public function getDirectGiving()
    {
        return $this->directGiving;
    }

    public function setDirectGiving($directGiving)
    {
        $this->directGiving = $directGiving;
    }

    public function getDirectGivingAdded()
    {
        return $this->directGivingAdded;
    }

    public function setDirectGivingAdded($directGivingAdded)
    {
        $this->directGivingAdded = $directGivingAdded;
    }

    public function getBetterButtonUID()
    {
        return $this->betterButtonUID;
    }

    public function setBetterButtonUID($betterButtonUID)
    {
        $this->betterButtonUID = $betterButtonUID;
    }

    public function getFacebookShareMessage()
    {
        return $this->facebookShareMessage;
    }

    public function setFacebookShareMessage($facebookShareMessage)
    {
        $this->facebookShareMessage = $facebookShareMessage;
    }

    public function getFacebookURL()
    {
        return $this->facebookURL;
    }

    public function setFacebookURL($facebookURL)
    {
        $this->facebookURL = $facebookURL;
    }

    public function getTwitterURL()
    {
        return $this->twitterURL;
    }

    public function setTwitterURL($twitterURL)
    {
        $this->twitterURL = $twitterURL;
    }

    public function getProjects()
    {
        return $this->projects;
    }

    public function addProject( $project )
    {
        $this->projects[] = $project;
    }

    public function getBetterButtonNonprofit()
    {
        return $this->betterButtonNonprofit;
    }

    public function setBetterButtonNonprofit($betterButtonNonprofit)
    {
        $betterButtonNonprofit->setSGNNonprofit($this);
        $this->betterButtonNonprofit = $betterButtonNonprofit;
    }

    // ===================================================================== //
    // Methods
    // ===================================================================== //

    public function __construct()
    {
        $this->projects = new ArrayCollection();
    }

    public function getTransactionFundsRaised() {}
    public function getMatchingFundsRaised() {}
    public function getTotalFundsRaised() {}


}
4

1 回答 1

2

您似乎引用了错误的实体名称,targetEntity="SGN\Models\BetterButtonTransaction" 应该是 targetEntity="name_of_the_table_as_is_in_the_database"。您不能映射到运行时实体,而是映射到数据库中的表名。

于 2013-07-17T19:23:53.330 回答