JMS中的ReflectionException [英] ReflectionException in JMS

查看:161
本文介绍了JMS中的ReflectionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在symfony开发一个简单的应用程序来学习symfony.It有条款,示例实体.TermExamples是一个更多的实体是一个更多的权限,它是Term和Examples之间的映射表。所有这些都很好,但是当我尝试序列化使用JMS序列化器,我得到一个反映异常
这些是我的实体



术语

  / ** 
*条款
*
* @ 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();
}
/ **
*获取id
*
* @return integer
* /
public function getId()
{
return $ this-> id;
}

/ **
*获取相关条款
* /
public function getRelatedTerms()
{
return $这个> relatedTerms;
}

/ **
*添加相关术语
* /
public function addRelatedTerm($ relatedTerm)
{
$ this-> relatedTerms [] = $ relatedTerm;
}

/ **
*清除相关条款
* /
public function clearRelatedTerms()
{
$ this - > relatedTerms->清除();
}

/ **
*删除相关的条款
* /
public function removeRelatedTerm($ relatedTerm)
{
$ this-> relatedTerms-> removeElement($ relatedTerm);
}

/ **
*获取术语示例
* /
public function getTermExamples()
{
return $ this-> termExamples;
}

/ **
*添加术语示例
* /
public function addTermExample($ termExample)
{
$ this-> termExamples [] = $ termExample;
}

/ **
*清除术语示例
* /
public function clearTermExamples()
{
$ this - > termExamples-> clear();
}

/ **
*删除术语示例
* /
public function removeTermExample($ termExample)
{
$ this-> termExamples-> removeElement($ termExample);
}

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

return $ this;
}

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

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

return $ this;
}

/ **
*获取描述
*
* @return string
* /
public function getDescription )
{
return $ this-> description;
}

/ **
*设置助记符
*
* @param string $ mnemonic
* @return Term
* /
public function setMnemonic($ mnemonic)
{
$ this-> mnemonic = $ mnemonic;

return $ this;
}

/ **
*获取助记符
*
* @return string
* /
public function getMnemonic )
{
return $ this-> mnemonic;
}



}

示例

  / ** 
*示例
*
* @ ORM\Table (name =examples)
* @ ORM\Entity
* /
class示例
{


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


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

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

/ **
*设置示例句
*
* @param string $ exampleSentence
* /
public函数setExampleSentence($ exampleSentence)
{
$ this-> exampleSentence = $ exampleSentence;

return $ this;
}

}

?>

TermExample

  / ** 
* TermExample
*
* @ ORM\Table(name =term_examples)
* @ ORM\Entity
* /
class TermExample
{
/ **
* @var整数
*
* @ 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()
{

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

/ **
*获取条件
*
* @return Term
* /
public function getTerm )
{
return $ this-> term;
}

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

/ **
*获取示例
*
* @return示例
* /
public function getExample )
{
return $ this-> example;
}

/ **
*设置示例
*
* @return TermExample
* /
public function setExample $ example)
{
$ this-> example = $ example;
}

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

/ **
*设置pos
*
* @param string $ pos - 演讲稿
* /
public function setPos($ pos)
{
$ this-> pos = $ pos;
}

}

当我尝试添加一个术语用例句,一切都进入数据库,但是当我尝试序列化这个术语时,它显示一个错误

 消息:Property Madhuri\\TermsBundle\\Entity\\TermExample :: $ exampleSentence不存在,
class:ReflectionException,
trace: [
{
namespace:,
short_class:,
class:,
type
function:,
file:/Users/madhuripalagummi/Documents/Dictionary/vendor/jms/metadata/src/Metadata/PropertyMetadata.php,
line :75,
args:[]
},

试图清除教义c疼痛的元数据。但仍然工作。
当我在 TermExample 实体中添加一个字段 $ exampleSentence 时,它工作。但为什么要有 TermExample 中的 $ exampleSentence
任何人都可以帮助我吗?

解决方案

JMS将其序列化缓存分开存储在Doctrine中,以便我尝试将缓存(即删除缓存目录的内容,而不仅仅是执行缓存:clear 命令),然后重试。这听起来像是串行器持有旧的注释。


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?

解决方案

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.

这篇关于JMS中的ReflectionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆