将使用复合外键作为主键的子实体保存为使用JMS Serializer反序列化时出错

gal*_*net 5 symfony doctrine-orm

我有一个像这样的JSON对象:

{
  "childEntity" : {
    "bar": "foo"
  },
  "someproperty" : "2.0"
}
Run Code Online (Sandbox Code Playgroud)

我使用JMS Serializer包来反序列化该对象并将其转换为Doctrine2对象:

$myObject = $serializer->deserialize($jsonStringJustAbove, "My\FooBundle\Entity\masterEntity", 'json');
$myObject = $em->merge($myObject);
$myObject->persist($tour);
$myObject->flush();
Run Code Online (Sandbox Code Playgroud)

这是我的"masterEntity"类:

class masterEntity {

 /**
     * @JMS\Type("ArrayCollection<My\FooBundle\Entity\childEntity>")
     * @ORM\OneToMany(targetEntity="childEntity", mappedBy="masterEntity", cascade={"remove", "persist", "merge"})
     */
    private $childentities;

 public function setChildEntities(ArrayCollection $childentities)
 {
     $this->childentities = $childentities;
 }

}
Run Code Online (Sandbox Code Playgroud)

这是我的"childEntity"类:

class childEntity {

 /**
     * @JMS\Type("My\FooBundle\Entity\masterEntity")
     * @ORM\ManyToOne(targetEntity="My\FooBundle\Entity\masterEntity", inversedBy="childEntities", cascade={"persist"})
     * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
     * @ORM\Id
     */
    private $masterEntity;

/**
     * @JMS\Type("My\FooBundle\Entity\barEntity")
     * @ORM\ManyToOne(targetEntity="My\FooBundle\Entity\barEntity")
     * @ORM\JoinColumn(nullable=false)
     * @ORM\Id
     */
    private $barEntity;

 public function setMasterEntity(masterEntity $masterEntity)
 {
     $this->masterEntity = $masterEntity;
 }

 public function setBarEntity(barEntity $barEntity)
 {
     $this->barEntity = $barEntity;
 }

}
Run Code Online (Sandbox Code Playgroud)

收到的我的JSON对象尚未存在于数据库中,与所有childEntities一样.

我希望反序列化器能够将masterEntity和他所有的孩子都准备好保存到数据库中.我的第一个问题是:序列化器和合并函数是这样的:

$masterEntity = new masterEntity();
$childEntity = new childEntity();
$childEntity->setMasterEntity($masterEntity);
$childEntity->setBarEntity($foo);
Run Code Online (Sandbox Code Playgroud)

我不确定,因为我在尝试保存masterEntity(第二个代码块)时收到此错误:

Notice: Undefined index: 0000000069332c43000000007c145082 in ../vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2740
Run Code Online (Sandbox Code Playgroud)

注意:我使用Symfony 2.1.8与Doctrine 2.3.2和JMS Serializer dev-master(2013年3月4日)

你能告诉我,我正在尝试做的是正确的,逻辑的和可能的吗?如果是,为什么我有这个错误?如何摆脱它?

谢谢.