JMS 中的反射异常

ReflectionException in JMS

我正在 symfony 中开发一个简单的应用程序来学习 symfony.It 有术语,示例 entities.TermExamples 是一个实体是另一个实体,它是术语和 [ 之间的映射 table =32=] 很好,但是当我尝试使用 JMS 序列化程序进行序列化时,出现反射异常 这些是我的实体

任期

/**
 * Term
 *
 * @ORM\Table(name="terms")
 * @ORM\Entity
 */
class Term
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="termName", type="string", length=255)
     */
    private $termName;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="string", length=2000)
     */
    private $description;

    /**
     * @var string
     *
     * @ORM\Column(name="mnemonic", type="string", length=2000)
     */
    private $mnemonic;

    /**
     * @var ArrayCollection
     *
     * @ORM\OneToMany(targetEntity="RelatedTerm",
     *                mappedBy="term1",cascade={"persist"})
     */
    private $relatedTerms;

    /**
     * @var ArrayCollection
     *
     * @ORM\OneToMany(targetEntity="TermExample",
     *                mappedBy="term",cascade={"persist"})
     */
    private $termExamples;


    public function __construct()
    {
      $this->relatedTerms = new ArrayCollection();
      $this->termExamples = new ArrayCollection();
    }
    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get Related Terms
     */
    public function getRelatedTerms()
    {
      return $this->relatedTerms ;
    }

    /**
     * Add related term
     */
    public function addRelatedTerm($relatedTerm)
    {
        $this->relatedTerms[] = $relatedTerm;
    }

    /**
     * Clear related Terms
     */
    public function clearRelatedTerms()
    {
        $this->relatedTerms->clear();
    }

    /**
     * Remove a related Term
     */
    public function removeRelatedTerm($relatedTerm)
    {
        $this->relatedTerms->removeElement($relatedTerm);
    }

    /**
     * Get Term Examples
     */
    public function getTermExamples()
    {
      return $this->termExamples ;
    }

    /**
     * Add term example
     */
    public function addTermExample($termExample)
    {
        $this->termExamples[] = $termExample;
    }

    /**
     * Clear term examples
     */
    public function clearTermExamples()
    {
        $this->termExamples->clear() ;
    }

    /**
     * Remove a Term Example
     */
    public function removeTermExample($termExample)
    {
        $this->termExamples->removeElement($termExample);
    }

    /**
     * Set termName
     *
     * @param string $termName
     * @return Term
     */
    public function setTermName($termName)
    {
        $this->termName = $termName;

        return $this;
    }

    /**
     * Get termName
     *
     * @return string
     */
    public function getTermName()
    {
        return $this->termName;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Term
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set mnemonic
     *
     * @param string $mnemonic
     * @return Term
     */
    public function setMnemonic($mnemonic)
    {
        $this->mnemonic = $mnemonic;

        return $this;
    }

    /**
     * Get mnemonic
     *
     * @return string
     */
    public function getMnemonic()
    {
        return $this->mnemonic;
    }



}

例子

/**
 * Example
 *
 * @ORM\Table(name="examples")
 * @ORM\Entity
 */
class Example
{


  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;

  /**
   * @var string
   *
   * @ORM\Column(name="example_sentence", type="string")
   */
  private $exampleSentence;


  /**
   * @var term
   *
   * @ORM\OneToMany(targetEntity="TermExample",
   *                mappedBy="example")
   */
  private $termExamples;


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

  /**
   * Get ExampleSentence
   *
   * @return string
   */
  public function getExampleSentence()
  {
    return $this->exampleSentence;
  }

  /**
   * Set Example sentence
   *
   * @param string $exampleSentence
   */
   public function setExampleSentence($exampleSentence)
   {
     $this->exampleSentence = $exampleSentence;

     return $this;
   }

}

 ?>

术语示例

/**
 * TermExample
 *
 * @ORM\Table(name="term_examples")
 * @ORM\Entity
 */
class TermExample
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Term",
     *                inversedBy="termExamples",
     *                cascade={"persist"})
     */
    private $term;

    /**
     * @ORM\ManyToOne(targetEntity="Example",
     *                inversedBy="termExamples",
     *                cascade={"persist"})
     */
    private $example;

    /**
     * @var string
     *
     * @ORM\Column(name="pos",nullable=true)
     */
    private $pos = "NO POS";

    //public $exampleSentence;


    public function __construct()
    {

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

    /**
     * Get Term
     *
     * @return Term
     */
    public function getTerm()
    {
      return $this->term ;
    }

    /**
     * Set Term
     * @param Term $term
     *
     * @return TermExample
     */
    public function setTerm($term)
    {
        $this->term = $term;
        $term->addTermExample($this);
    }

    /**
     * Get Example
     *
     * @return Example
     */
    public function getExample()
    {
      return $this->example ;
    }

    /**
     * Set Example
     *
     * @return TermExample
     */
    public function setExample($example)
    {
        $this->example = $example;
    }

    /**
     * Get pos
     *
     * @return string
     */
    public function getPos()
    {
      return $this->pos ;
    }

    /**
     * Set pos
     *
     * @param string $pos -Parts of speech
     */
    public function setPos($pos)
    {
        $this->pos = $pos;
    }

}

当我尝试添加带有例句的术语时,数据库中一切正常,但是当我尝试序列化该术语时,它显示错误

"message": "Property Madhuri\TermsBundle\Entity\TermExample::$exampleSentence does not exist",
                "class": "ReflectionException",
                "trace": [
                    {
                        "namespace": "",
                        "short_class": "",
                        "class": "",
                        "type": "",
                        "function": "",
                        "file": "/Users/madhuripalagummi/Documents/Dictionary/vendor/jms/metadata/src/Metadata/PropertyMetadata.php",
                        "line": 75,
                        "args": []
                    },

我尝试清除教义缓存 metadata.But 仍然有效。 当我在 TermExample 实体中添加字段 $exampleSentence 时,它 worked.But 为什么 TermExample 中应该有一个 $exampleSentence? 谁能帮帮我?

JMS 将其序列化缓存单独存储到 Doctrine 中,因此我会尝试闪电式缓存(即删除缓存目录的内容,而不仅仅是执行 cache:clear 命令)并重试。听起来序列化程序保留了旧注释。