[英]Error with id on INSERT INTO entity on Doctrine2/Symfony2
[英]Symfony2 doctrine2 insert record [Semantical Error] The annotation
尝试将记录插入原则时,记录正在插入,但出现错误:
[语义错误]属性C2Educate \\ ToolsBundle \\ Entity \\ StudentScores :: $ id中的注释“ @Expose”从未导入。 您是否可能忘了为此注释添加“ use”语句? (500内部服务器错误)
实体 :
<?php
namespace C2Educate\ToolsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\SerializerBundle\Annotation\Type;
/**
* C2Educate\ToolsBundle\Entity\StudentScores
*
* @ORM\Table(name="tbl_student_scores")
* @ORM\Entity
*/
class StudentScores {
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="tbl_student_scores_id_seq", allocationSize="1", initialValue="1")
* @Expose
* @Type("integer")
*/
protected $id;
/**
* @var integer $studentId
*
* @ORM\Column(name="student_id", type="integer", nullable=true)
* @Assert\NotBlank()
* @Type("integer")
*/
private $studentId;
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set studentId
*
* @param string $studentId
*/
public function setStudentId($studentId) {
$this->studentId = $studentId;
}
/**
* Get studentId
*
* @return string
*/
public function getStudentId() {
return $this->studentId;
}
}
控制器脚本:
$em = $this->getDoctrine()->getEntityManager();
$sc = new StudentScores();
$sc->setScore((!empty($test->composite) ? $test->composite : 0));
$sc->setTestDate($test->test_date);
$sc->setcreatedBy($loggedinUser);
$sc->setCreatedAt($date);
$sc->setupdatedBy($loggedinUser);
$sc->setUpdatedAt($date);
$sc->setStudentId($returnID);
$em->persist($sc);
$em->flush();
您忘记了添加错误声明中所述的use语句。 尝试这个
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.