dongxu198714 2014-10-23 13:36
浏览 45

学说不能删除实体

I face exception when I'm trying to remove entity with the help of Doctrine.

Here is my code:

if ($id > 0) {
    $phase = $em->find("Phase", $id);
    if ($phase instanceof Phase) {
        $picture = $phase->getPicture();
        if ($picture != "")
            deleteFile($dir . getPhotoSrc($picture));
        $logo = $phase->getLogo();
        if ($picture != "")
            deleteFile($dir . getPhotoSrc($logo));
        $logo2 = $phase->getLogo2();
        if ($picture != "")
            deleteFile($dir . getPhotoSrc($logo2));
        $em->remove($phase);
        $em->flush();
    }
}

This is the error I'm getting

Entity was not found.

#0 /home/www/html/v3/admin/proxies/__CG__Phase.php(108): Doctrine\ORM\Proxy\ProxyFactory->Doctrine\ORM\Proxy\{closure}(Object(Proxies\__CG__\Phase), '__load', Array)
#1 /home/www/html/v3/admin/proxies/__CG__Phase.php(108): Closure->__invoke(Object(Proxies\__CG__\Phase), '__load', Array)
#2 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2268): Proxies\__CG__\Phase->__load()
#3 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Proxies\__CG__\Phase), Array)
#4 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Proxies\__CG__\Phase), Array)
#5 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Proxies\__CG__\Plan), Array)
#6 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Proxies\__CG__\Plan), Array)
#7 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Proxies\__CG__\Phase), Array)
#8 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Proxies\__CG__\Phase), Array)
#9 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Plan), Array)
#10 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2292): Doctrine\ORM\UnitOfWork->doRemove(Object(Plan), Array)
#11 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1692): Doctrine\ORM\UnitOfWork->cascadeRemove(Object(Phase), Array)
#12 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(1663): Doctrine\ORM\UnitOfWork->doRemove(Object(Phase), Array)
#13 /home/www/html/v3/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(647): Doctrine\ORM\UnitOfWork->remove(Object(Phase))
#14 /home/www/html/v3/admin/project_action.php(218): Doctrine\ORM\EntityManager->remove(Object(Phase))
#15 {main}

In class Plan I have:

/**
 * @ManyToMany(targetEntity="Phase", inversedBy="plans", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
 * @JoinTable(name="links_plan_phase",
 *      joinColumns={@JoinColumn(name="plan_id", referencedColumnName="id")},
 *      inverseJoinColumns={@JoinColumn(name="phase_id", referencedColumnName="id")}
 *      )
 **/
protected $phases;

In class Phase I have:

/**
 * @ManyToMany(targetEntity="Plan", mappedBy="phases", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
 **/
private $plans;

I'm finally confused. Can anybody help me to find where is the problem and how ca I solve it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog