我正在symfony开发一个简单的应用程序来学习symfony.It有条款,示例实体.TermExamples是另一个实体是另一个权利,它是Term和Examples之间的映射表。一切都很好但是当我尝试序列化时使用JMS序列化程序,我得到一个Reflection异常 这些是我的实体
期限
/**
* 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
/**
* 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": []
},
我尝试清除doctrine缓存元数据。但仍然工作。
当我在$exampleSentence
实体中添加了一个字段TermExample
时,它就有效了。但为什么$exampleSentence
中应该有一个TermExample
?
有人可以帮帮我吗?
答案 0 :(得分:2)
JMS将其序列化缓存分别存储到Doctrine中,因此我会尝试闪存缓存(即删除缓存目录的内容,而不仅仅是执行cache:clear
命令)并再次尝试。听起来好像序列化程序正在坚持使用旧注释。