ReflectionException in JMS

試著忘記壹切 提交于 2019-12-12 01:27:37

问题


I am developing a simple app in symfony to learn symfony.It has Terms,Example entities.TermExamples is one more entity is one more entitty which is a mapping table between Term and Examples.All is fine but when i try to serialize using JMS serializer ,I get a Reflection exception These are my entities

Term

/**
 * 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

/**
 * 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

/**
 * 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;
    }

}

When i try to add a term with example sentence,Everything goes fine into the db,but when i try to serialise the term, It shows me an error

"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": []
                    },

I tried clearing the doctrine cache metadata.But still dint work. And when i added a field $exampleSentence in TermExample entity,It worked.But why should there be a $exampleSentence in TermExample? Can anyone please help me?


回答1:


JMS stores its serialization cache separately to Doctrine so I would try blitzing your cache (i.e. deleting the contents of the cache directory, not just doing a cache:clear command) and trying again. It sounds like the serializer is holding on to old annotations.



来源:https://stackoverflow.com/questions/31906530/reflectionexception-in-jms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!