symfony - 通知 : Object of class Doctrine\ORM\EntityManager could not be converted to int

标签 symfony doctrine entitymanager

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

实体

    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;

我尝试在我的 Controller 中像这样更新:

$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');
    }

我对其他实体也做了同样的事情,没问题,我不知道这个有什么问题。我验证了 Doctrine 模式,没有错。

最佳答案

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

关于symfony - 通知 : Object of class Doctrine\ORM\EntityManager could not be converted to int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28529752/

相关文章:

php - 表单域不显示

php - 缓存不工作

php - MySQL 保存到数据库 Symfony2 时出错

php - MongoDB 功能测试设置和拆卸在 4.2 中使用 WiredTiger 慢 10 倍

java - Spring 启动/JavaFX : adding a shutdown hook (ctrl-c) that still has access to JPA

mysql - 如何在 TomEE 中的 java 应用程序中连接 MySQL 数据库

Symfony 缓存组件 - Redis 适配器

validation - 发布前表单验证

java - 实体管理器未持久保存在数据库中

symfony - 在 EasyAdmin 3.x 中使用 autocomplete() 时如何设置 AssociationField 选择标签