【问题标题】:Notice: Object of class Doctrine\ORM\EntityManager could not be converted to int注意:Doctrine\ORM\EntityManager 类的对象无法转换为 int
【发布时间】:2015-02-15 18:46:10
【问题描述】:

我在尝试更新对象时偶然发现了这个错误,但找不到任何解释。这是我的代码:

实体

    namespace Mnv\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Class UtilitatiVariabile
 * @package Mnv\CoreBundle\Entity
 *
 * @ORM\Table(name="utilitati_variabile")
 * @ORM\Entity(repositoryClass="Mnv\CoreBundle\Entity\Repository\UtilitatiVariabileRepository")
 */
class UtilitatiVariabile {

    /**
     * @var integer
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @var float
     *
     * @ORM\Column(type="decimal", precision=10, scale=6, nullable=true)
     */
    protected $coeficient;

    /**
     * @var float
     *
     * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $kwh;

    /**
     * @var float
     *
     * @ORM\Column(name="original_kwh", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $originalKwh;

    /**
     * @var float
     *
     * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $mc;

    /**
     * @var float
     *
     * @ORM\Column(name="original_mc", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $originalMc;

    /**
     * @var float
     *
     * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $lei;

    /**
     * @var float
     *
     * @ORM\Column(name="original_lei", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $originalLei;

    /**
     * @var float
     *
     * @ORM\Column(type="decimal", precision=10, scale=6, nullable=true)
     */
    protected $leikw;

    /**
     * @var float
     *
     * @ORM\Column(type="decimal", precision=10, scale=6, nullable=true)
     */
    protected $leimc;

    /**
     * @var float
     *
     * @ORM\Column(name="suprafata_totala", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $suprafataTotala;

    /**
     * @var float
     *
     * @ORM\Column(name="total_col_mc", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColMc;

    /**
     * @var float
     *
     * @ORM\Column(name="total_col_kwh", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColKwh;

    /**
     * @var float
     *
     * @ORM\Column(name="total_col_lei", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColLei;

    /**
     * @var float
     *
     * @ORM\Column(name="total_col_total", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColTotal;

    /**
     * @var Utilitati
     *
     * @ORM\ManyToOne(targetEntity="Utilitati")
     * @ORM\JoinColumn(name="id_utilitate", referencedColumnName="id", onDelete="SET NULL")
     */
    protected $utilitate;

    /**
     * @var SesiuneUtilitati
     *
     * @ORM\ManyToOne(targetEntity="SesiuneUtilitati")
     * @ORM\JoinColumn(name="id_sesiune", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $sesiuneUtilitati;

我试图在我的控制器中像这样更新:

$variables = $this->getVariabileRepository()->find(1);
$variables->setKwh($kwh);
        .
        .
        .
        $em = $this->getEntityManager();
        $em->persist($variables);
        $em-flush();




   protected function getEntityManager()
        {
            return $this->getDoctrine()->getManager();
        }

    protected function getVariabileRepository()
    {
        return $this->getEntityManager()->getRepository('MnvCoreBundle:UtilitatiVariabile');
    }

我对其他实体做了同样的事情,没问题,我不知道这个有什么问题。我验证了学说架构,没有错。

【问题讨论】:

    标签: symfony doctrine entitymanager


    【解决方案1】:

    我想我太累了,没注意到该死的 $em-flush 错字:))) 好家伙!这是一个奇怪的错误,我花了 30 分钟试图找出这个错误,从来没有怀疑过错字。希望有一天它可以挽救某人的生命:))

    【讨论】:

    • 天哪,有完全相同的类型。我的 IDE 甚至突出显示了它。睡眠不仅是一种乐趣,而且显然是必要的。
    猜你喜欢
    • 1970-01-01
    • 2016-01-11
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-16
    • 1970-01-01
    • 2019-05-02
    相关资源
    最近更新 更多