在链配置的命名空间中找不到类“Doctrine\ORM\PersistentCollection”

use*_*505 5 orm doctrine-orm zend-framework2

我在项目 Zend Framework 2 中使用 Doctrine 2 ORM。我正在努力保持多对多关系。我遵循了此处描述的文档(很多)。在尝试保留数据时:$em->persist($form->getData());我收到错误:

"The class 'Doctrine\ORM\PersistentCollection' was not found in the chain configured namespaces".
Run Code Online (Sandbox Code Playgroud)

有什么建议 ?

为了更清楚,我在下面添加了一些代码:

首先,我注释了像文档所说的实体,对于多对多关系:

 /**
 * @ORM\ManyToMany(targetEntity="\User\Entity\Client", mappedBy="reportSettings")
 */
private $client;

public function __construct() {
    $this->client = new ArrayCollection();
}
Run Code Online (Sandbox Code Playgroud)

/**
 * @ORM\ManyToMany(targetEntity="\Statistics\Entity\ReportSettings", inversedBy="client")
 * @ORM\JoinTable(name="report_client_settings",
 *      joinColumns={@ORM\JoinColumn(name="client_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="report_setting_id", referencedColumnName="id")})
 */
private $reportSettings;

public function __construct() {
    $this->reportSettings = new ArrayCollection();
}
Run Code Online (Sandbox Code Playgroud)

并在控制器中

$form = new UpdateReportSettingsForm();

    $form->bind($reportSettings);

    $request = new Request();

    if ($request->isPost()) {
        $form->setData($request->getPost());

        if ($form->isValid()) {
         $data = $form->getData();
          $em->persist($data); // here I got the error - The class 'Doctrine\ORM\PersistentCollection' was not found in the chain configured namespaces
          $em->flush();
Run Code Online (Sandbox Code Playgroud)

}

我还以 DoctrineModule\Form\Element\ObjectMultiCheckbox 的形式使用。一个简单的var_dump($data)- 返回一个持久集合。

125*_*369 -1

您是否在要映射的实体的开头添加了这段代码

use Doctrine\Common\Collections\ArrayCollection;
Run Code Online (Sandbox Code Playgroud)