注意:类DoctrineORMEntityManager的对象无法转换为int



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

实体

    namespace MnvCoreBundleEntity;
use DoctrineORMMapping as ORM;
/**
 * Class UtilitatiVariabile
 * @package MnvCoreBundleEntity
 *
 * @ORMTable(name="utilitati_variabile")
 * @ORMEntity(repositoryClass="MnvCoreBundleEntityRepositoryUtilitatiVariabileRepository")
 */
class UtilitatiVariabile {
    /**
     * @var integer
     *
     * @ORMId()
     * @ORMGeneratedValue(strategy="AUTO")
     * @ORMColumn(type="integer")
     */
    protected $id;
    /**
     * @var float
     *
     * @ORMColumn(type="decimal", precision=10, scale=6, nullable=true)
     */
    protected $coeficient;
    /**
     * @var float
     *
     * @ORMColumn(type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $kwh;
    /**
     * @var float
     *
     * @ORMColumn(name="original_kwh", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $originalKwh;
    /**
     * @var float
     *
     * @ORMColumn(type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $mc;
    /**
     * @var float
     *
     * @ORMColumn(name="original_mc", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $originalMc;
    /**
     * @var float
     *
     * @ORMColumn(type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $lei;
    /**
     * @var float
     *
     * @ORMColumn(name="original_lei", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $originalLei;
    /**
     * @var float
     *
     * @ORMColumn(type="decimal", precision=10, scale=6, nullable=true)
     */
    protected $leikw;
    /**
     * @var float
     *
     * @ORMColumn(type="decimal", precision=10, scale=6, nullable=true)
     */
    protected $leimc;
    /**
     * @var float
     *
     * @ORMColumn(name="suprafata_totala", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $suprafataTotala;
    /**
     * @var float
     *
     * @ORMColumn(name="total_col_mc", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColMc;
    /**
     * @var float
     *
     * @ORMColumn(name="total_col_kwh", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColKwh;
    /**
     * @var float
     *
     * @ORMColumn(name="total_col_lei", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColLei;
    /**
     * @var float
     *
     * @ORMColumn(name="total_col_total", type="decimal", precision=20, scale=2, nullable=true)
     */
    protected $totalColTotal;
    /**
     * @var Utilitati
     *
     * @ORMManyToOne(targetEntity="Utilitati")
     * @ORMJoinColumn(name="id_utilitate", referencedColumnName="id", onDelete="SET NULL")
     */
    protected $utilitate;
    /**
     * @var SesiuneUtilitati
     *
     * @ORMManyToOne(targetEntity="SesiuneUtilitati")
     * @ORMJoinColumn(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');
    }

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

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

最新更新