Doctrine EntityManager find()方法返回null

时间:2015-12-29 22:31:01

标签: php symfony doctrine-orm

我正在使用dflydev Doctrine ORM Service Provider 。如果我使用find方法,我会null

$this->em->find('SilexTemplate\Entity\Theme', $id);

我使用的ID是1,它存在于数据库中。如果我使用createQueryBuilder方法,我会正确获得实体:

    $queryBuilder = $this->em->createQueryBuilder();
    $query = $queryBuilder->select('em')
        ->from('SilexTemplate\Entity\Theme', 'em')
        ->getQuery();

    return $query->getResult();

这是相应的主题实体:

<?php
namespace SilexTemplate\Entity;

/**
 * Class Theme
 *
 * @package SilexTemplate\Entity
 *
 * @\Doctrine\ORM\Mapping\Entity()
 * @\Doctrine\ORM\Mapping\Table(name="theme")
 */
class Theme
{
/**
 * The primary key for this entity
 *
 * @var int
 *
 * @\Doctrine\ORM\Mapping\Id
 * @\Doctrine\ORM\Mapping\Column(type="integer", name="id")
 * @\Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * The menu background color
 *
 * @var integer
 *
 * @\Doctrine\ORM\Mapping\Column(type="integer", name="menuBackgroundColor", nullable=false)
 * @OneToOne(targetEntity="rgba", mappedBy="id")
 */
private $menuBackgroundColor;

/**
 * The menu Font Color
 *
 * @var integer
 *
 * @\Doctrine\ORM\Mapping\Column(type="integer", name="menuFontColor", nullable=false)
 * @OneToOne(targetEntity="rgba", mappedBy="id")
 */
private $menuFontColor;

/**
 * Is the menu Fixed ?
 *
 * @var boolean
 *
 * @\Doctrine\ORM\Mapping\Column(type="boolean", name="menuFixed", nullable=false)
 */
private $menuFixed;

/**
 * Is the footer Fixed ?
 *
 * @var boolean
 *
 * @\Doctrine\ORM\Mapping\Column(type="boolean", name="footerFixed", nullable=false)
 */
private $footerFixed;

/**
 * The background color
 *
 * @var integer
 *
 * @\Doctrine\ORM\Mapping\Column(type="integer", name="backgroundColor", nullable=false)
 * @OneToOne(targetEntity="rgba", mappedBy="id")
 */
private $backgroundColor;

/**
 * The font color
 *
 * @var integer
 *
 * @\Doctrine\ORM\Mapping\Column(type="integer", name="fontColor", nullable=false)
 * @OneToOne(targetEntity="rgba", mappedBy="id")
 */
private $fontColor;

/**
 * @param int $id
 */
public function setId($id)
{
    $this->id = $id;
}

/**
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * @return int
 */
public function getMenuBackgroundColor()
{
    return $this->menuBackgroundColor;
}

/**
 * @param int $menuBackgroundColor
 */
public function setMenuBackgroundColor($menuBackgroundColor)
{
    $this->menuBackgroundColor = $menuBackgroundColor;
}

/**
 * @return int
 */
public function getMenuFontColor()
{
    return $this->menuFontColor;
}

/**
 * @param int $menuFontColor
 */
public function setMenuFontColor($menuFontColor)
{
    $this->menuFontColor = $menuFontColor;
}

/**
 * @return boolean
 */
public function isMenuFixed()
{
    return $this->menuFixed;
}

/**
 * @param boolean $menuFixed
 */
public function setMenuFixed($menuFixed)
{
    $this->menuFixed = $menuFixed;
}

/**
 * @return boolean
 */
public function isFooterFixed()
{
    return $this->footerFixed;
}

/**
 * @param boolean $footerFixed
 */
public function setFooterFixed($footerFixed)
{
    $this->footerFixed = $footerFixed;
}

/**
 * @return int
 */
public function getBackgroundColor()
{
    return $this->backgroundColor;
}

/**
 * @param int $backgroundColor
 */
public function setBackgroundColor($backgroundColor)
{
    $this->backgroundColor = $backgroundColor;
}

/**
 * @return int
 */
public function getFontColor()
{
    return $this->fontColor;
}

/**
 * @param int $fontColor
 */
public function setFontColor($fontColor)
{
    $this->fontColor = $fontColor;
}
}

0 个答案:

没有答案