映射多对一关系会导致MappingException

时间:2011-12-10 15:57:08

标签: symfony doctrine doctrine-orm

我遇到了映射我以前从未遇到的多对一关系的问题。

信息:

  • 我尝试生成数据库方案时遇到的异常是:

      

    [学说\ ORM \映射\ MappingException]
      类Monkeyproof \ Uploaderbundle \ Entity \ Folder不是有效实体   或映射超类。

  • GroupPermission有一个文件夹

  • 我正在使用XML映射
  • 文件夹是 Entity 的子类,在我添加新关系之前,它已正确映射,因为它正常工作。

以下是我的映射文件:

GroupPermission.orm.xml:

<?xml version="1.0" encoding="utf-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                  http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Monkeyproof\UploaderBundle\Entity\GroupPermission">

        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>

        <field name="permissionType" type="integer" nullable="false" />

        <many-to-one target-entity="Folder" field="folder" />
    </entity>

</doctrine-mapping>

Folder.orm.xml:

<?xml version="1.0" encoding="utf-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Monkeyproof\UploaderBundle\Entity\Folder"
        repository-class="Monkeyproof\UploaderBundle\Repository\FolderRepository">

    <one-to-many target-entity="Entry" mapped-by="parentFolder" field="content">
        <cascade>
            <cascade-persist/>
            <cascade-remove/>
        </cascade>
    </one-to-many>
</entity>

在我的GroupPermission实体中:

/**
 * @var \Monkeyproof\UploaderBundle\Entity\Folder
 */
protected $folder;

1 个答案:

答案 0 :(得分:0)

Class Monkeyproof\Uploaderbundle\Entity\Folder is not a valid entity or mapped super class.

1)确保Monkeyproof \ Uploaderbundle \ Entity \ Folder是一个实体,即

// Monkeyproof\Uploaderbundle\Entity\Folder
/**
 * @ORM\Entity
 */
 class Folder {..}

2)这不太可能,因为您提到它曾经工作但是当您不使用自动映射和使用显式em时可能会导致此错误。你有以下配置吗?

doctrine:
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        default_entity_manager: default
        entity_managers:
            default:
                mappings:
                    MonkeyproofUploaderBundle: ~

3)最后,确保清除缓存,包括apc(如果您正在使用它)。