Symfony doctrine实体插入错误

时间:2014-01-02 12:29:10

标签: php symfony doctrine-orm

我真的很奇怪插入实体

有问题 在foreach中

使用此代码:

public function setGate($keyId, $elementId, $keywordType){

    echo "<BR>setGate $keyId , $elementId";
    if(!intval($keyId) or !intval($elementId))
        throw new MeaException("$keyId,$elementId Keywords setGate empty");

    $gate = $this->repositoryGate
        ->createQueryBuilder('e')
            ->select('e.id')
            ->where('e.mkeywords_id=:keyid and e.elid=:elid')
            ->setParameters(array('keyid'=>$keyId,'elid'=>$elementId))
            ->getQuery()
        ->getOneOrNullResult();

    if($gate) return true;

    $gateObj = new KeywordsGate();

    $gateObj->setElid($elementId);
    $gateObj->setMkeywordsId($keyId);
    $gateObj->setMkeywordstypeId($keywordType);

    $this->em->persist($gateObj);

    try {
        $this->em->flush();
    }catch (\Exception $e){
        var_dump($gateObj);
        var_dump($e);
        die('e');
    }

    return $this;
}

在每个i回声数字上:

echo "<BR>setGate $keyId , $elementId"; 

有:

setGate 1558 , 5922
setGate 1348 , 5922
....
setGate 1474 , 5922
setGate 1475 , 5922
setGate 1476 , 5922

并且在一个元素上有错误:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'mkeywords_id' cannot be null'

并拥有屏幕:

object(Miejsce\KeywordsBundle\Entity\KeywordsGate)[1206]
  private 'id' => null
  private 'mkeywords_id' => int 1476
  private 'elid' => string '5922' (length=4)
  private 'mkeywordstype_id' => int 4
  private 'keywordElement' => null

object(Doctrine\DBAL\DBALException)[1208]
  protected 'message' => string 'An exception occurred while executing 'INSERT INTO mKeywordsGate (mkeywords_id, elid, mkeywordstype_id) VALUES (?, ?, ?)' with params [null, "5922", 4]:

那么哪里可以出错?

0 个答案:

没有答案