title: A new entity was found through the relationship that was not configured to cascade persist operations for entit
body: <p>New to doctrine, trying to insert object that has <code>ManyToOne</code> rel into database, but getting errors. Writing relevant code below:</p>
  
  <p>Controller:</p>
  
  <pre><code>    $oPost    = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:RedditPost')-&gt;findOneById(5);
      $oComment = new \AppBundle\Entity\Comments();
      $oComment-&gt;setComment('4');
      $oComment-&gt;setCreated('2016-11-12');
      $oPost-&gt;addComment($oComment);
  
      $oEm = $this-&gt;getDoctrine()-&gt;getManager();
      $oEm-&gt;persist($oPost);
      $oEm-&gt;flush(); //  -- getting error here
  </code></pre>
  
  <p>Entity\RedditPost:</p>
  
  <pre><code>public function __construct()
  {
      $this-&gt;comments = new ArrayCollection();
  }
  
  /**
   * @ORM\OneToMany(targetEntity="AppBundle\Entity\Comments", mappedBy="post")
   */
  protected $comments;
  
  public function addComment(Comments $comments)
  {
      if (!$this-&gt;comments-&gt;contains($comments)) {
          $comments-&gt;setPost($this);
          $this-&gt;comments-&gt;add($comments);
      }
  
      return $this;
  }
  </code></pre>
  
  <p>Entity\Comments:</p>
  
  <pre><code>/**
   * @ORM\ManyToOne(targetEntity="AppBundle\Entity\RedditPost", inversedBy="comments")
   * @ORM\JoinColumn(name="post_id", referencedColumnName="id")
   */
  protected $post;
  
  public function setPost(RedditPost $post)
  {
      $this-&gt;post = $post;
  
      return $this;
  }
  </code></pre>
  
  <p>Full error:</p>
  
  <p><code>A new entity was found through the relationship 'AppBundle\Entity\RedditPost#comments' that was not configured to cascade persist operations for entity: AppBundle\Entity\Comments@000000005d78d3ae00000000b58ca229. 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 'AppBundle\Entity\Comments#__toString()' to get a clue.</code></p>
  
  <p>What i tried and notes:</p>
  
  <ul>
  <li>From the error, i tried adding the <code>,cascade={"persist"}</code> value to Comments entity, but error didnt change at all</li>
  <li>Tried making 2 persist calls in controller <code>$oEm-&gt;persist($oPost); $oEm-&gt;persist($oComment);</code> - but i get <code>ERR_CONNECTION_RESET</code> error and cant debug from there.</li>
  <li>I checked my database and all the relations are there, everything seems fine.</li>
  <li>I can insert into RedditPost entity without problems. </li>
  <li>Tried clearing cache.</li>
  </ul>
  
  <hr>
  
  <p>Made new attempt at this, still same results:</p>
  
  <pre><code>class Owner {
  
    public function __construct()
    {
      $this-&gt;children = new ArrayCollection();
    }
  
    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Child", mappedBy="owner")
     */
    protected $children;
  
    public function addChild(Child $child)
    {
      if (!$this-&gt;children-&gt;contains($child)) {
        $child-&gt;setOwner($this);
        $this-&gt;children-&gt;add($child);
      }
  
      return $this;
    }
  }
  
  class Child {
  
    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Owner", inversedBy="children", cascade={"persist"})
     * @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
     */
    protected $owner;
  
    /**
     * @param mixed $owner
     */
    public function setOwner(Owner $owner)
    {
      $this-&gt;owner = $owner;
  
      return $this;
    }
  }
  
  class DefaultController extends Controller
  {
         public function indexAction()
         {
                $owner = new Owner();
                $child = new Child();
                $child-&gt;setName('test');
                $owner-&gt;addChild($child);
                $em = $this-&gt;getDoctrine()-&gt;getManager();
                $em-&gt;persist($owner);
                $em-&gt;flush();
         }
  }
  </code></pre>
  
  <hr>
  
  <p>Current solution is to remove <code>@ORM\OneToMany</code> completely, that way i can insert to database without problems.</p>