Doctrine MappingException with message'目标实体Entity \\ ItemsBags在' Entity \\ Players#itemsBag'

时间:2017-09-05 10:39:22

标签: php doctrine-orm backend

美好的一天。我已经在第二天了,我无法理解其中的问题......我在运行时收到错误:

  

PHP致命错误:未捕获的异常   '学说\ ORM \映射\ MappingException'有消息' The   目标实体Entity \ ItemsBags无法找到   '实体\玩家#itemsBag''在   /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:762       堆栈跟踪:       #0 /无功/网络/供应商/教义/ ORM / LIB /学说/ ORM /映射/ ClassMetadataInfo.php(1028):   学说\ ORM \制图\ MappingException :: invalidTargetEntityClass('实体\\ ItemsBag ...&#39 ;,   '实体\\玩家',' itemsBag')       #1 /无功/网络/供应商/教义/ ORM / LIB /学说/ ORM /映射/ ClassMetadataFactory.php(272):   教义\ ORM \映射\ ClassMetadataInfo-> validateAssociations()       #2 /无功/网络/供应商/教义/ ORM / LIB /学说/ ORM /映射/ ClassMetadataFactory.php(251):   教义\ ORM \映射\ ClassMetadataFactory-> validateRuntimeMetadata(对象(学说\ ORM \映射\ ClassMetadata),   空值)       #3 /无功/网络/供应商/教义/普通/ LIB /学说/普通/持久性/映射/ AbstractClassMetadataFactory.php(332):   Doctrine \ ORM \ Mapping \ ClassMetadataFactory-> doLoadM in   /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php   在762行

当我检查学说和更新时,一切顺利:

  

root @ comp:#php vendor / bin / doctrine orm:schema:update --force更新   数据库架构...数据库架构更新成功! " 4"查询   被处决了

  

root @ comp:#php vendor / bin / doctrine orm:validate-schema [Mapping]好的    - 映射文件是正确的。 [数据库]正常 - 数据库架构与映射文件同步。

我尝试清除缓存,删除代理并重新生成它们,但没有任何结果......

root@comp:# php vendor/bin/doctrine orm:clear-cache:metadata
Clearing ALL Metadata cache entries
Successfully deleted cache entries.
root@comp:# php vendor/bin/doctrine orm:clear-cache:query
Clearing ALL Query cache entries
Successfully deleted cache entries.
root@comp:# php vendor/bin/doctrine orm:clear-cache:result
Clearing ALL Result cache entries
Successfully deleted cache entries.
root@comp:# php vendor/bin/doctrine orm:generate-proxies
Processing entity "Entity\Objects"
Processing entity "Entity\Weapons"
Processing entity "Entity\ItemsBags"
Processing entity "Entity\Players"
Processing entity "Entity\Translations"
Processing entity "Entity\Worlds"
Processing entity "Entity\Tiles"
Processing entity "Entity\WorldStructures"

Proxy classes generated to "/tmp"

Players.php

namespace Entity;
use Doctrine\Common\Collections\ArrayCollection;

/**
 *
 * @Entity
 * @Table(name="players")
 *
 */
class Players{

    ...

    /**
     * @var ItemsBags
     *
     * @OneToOne(targetEntity="ItemsBags", mappedBy="player")
     */
    private $itemsBag;

    ...
}

ItemsBags.php

namespace Entity;
use Doctrine\Common\Collections\ArrayCollection;

/**
 *
 * @Entity
 * @Table(name="item_bags")
 *
 */
class ItemsBags{

    ...

    /**
     * @var Players
     *
     * @OneToOne(targetEntity="Players", inversedBy="itemsBag")
     * @JoinColumn(name="player_id", referencedColumnName="id")
     */
    private $player;

    ...

}

请告诉我,我做错了什么?

1 个答案:

答案 0 :(得分:1)

感谢@Sarcoma。我忘了在composer.json中指定自动加载部分

  "autoload": {
    "psr-4": { "": "core/" }
  },

P.S可以告诉我,为什么我的项目之前正常运行?)在我有很多内容之前,我的composer.json中没有那个部分,但一切正常。