0
votes

When trying to insert a record to doctrine, records is inserting but i am getting an error :

[Semantical Error] The annotation "@Expose" in property C2Educate\ToolsBundle\Entity\StudentScores::$id was never imported. Did you maybe forget to add a "use" statement for this annotation? (500 Internal Server Error)

Entity :

<?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;
}
}

Controller Script :

$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();
1

1 Answers

2
votes

You forgot to add use statements as it says in error description. Try this

use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;