I have an entity "Entity1", that have an OneToOne (one-direction) relation with another entity "Entity2". Entity2 is managed by a different EntityManager.
Here is part of the Entity1:
/**
* @ORM\OneToOne(targetEntity="Entity2")
* @ORM\JoinColumn(name="Entity2ID", referencedColumnName="ID")
**/
protected $entity2;
Entity2 already exists, Entity1 is a new entity. Here is part of the persisting logic:
$obj1 = new Entity1();
$obj1->setEntity2($this->entity2Manager
->getRepository('VendorBunlde:Entity2')
->find($entity2Id));
$this->entity1Manager->persist($obj1);
$this->entity1Manager->flush();
I got this error:
A new entity was found through the relationship 'MyBundle\\Entity\\Entity1#entity2' that was not configured to cascade persist operations for entity: VendorBundle\\Entity\\Entity2@0000000008fbb41600007f3bc3681401. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={\"persist\"}). If you cannot find out which entity causes the problem implement 'VendorBundle\\Entity\\Entity2#__toString()' to get a clue
How can I force Doctrine to skip persisting Entity2 and in the same time keep the relation? I tried "->merge($obj1)" it works but I get null when I call $obj1->getId()?!