title: "Not null violation: 7" when using manyToOne and oneToMany relations on Doctrine2
body: <p>I have a very basic schema like this:</p>
  
  <p><strong>Comments.yml:</strong></p>
  
  <pre><code>manyToOne:
    pages:
      targetEntity: Pages
      inversedBy: comments
      joinColumn:
        name: page_id
        referencedColumnName: idx
  
  ... other things ...
  </code></pre>
  
  <p><strong>Pages.yml:</strong></p>
  
  <pre><code>oneToMany:
    comments:
      targetEntity: Comments
      mappedBy: pages
      cascade: ["persist"] // i added this later but has no effect for both persist and merge.
      orderBy:
        idx: desc
  
  ... other things ...
  </code></pre>
  
  <p>Now, everything is working just fine. I  can get <code>Pages</code> from <code>Comments</code> and <strong>reverse</strong>. The problem is, when i try to insert a <strong>new</strong> row to the database, it says <code>page_id</code> is <code>null</code>.</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>$comment = new Comments();
  $comment-&gt;setPageId(2); // it is "2"
  $comment-&gt;setText($textData);
  
  $this-&gt;_em-&gt;persist($comment);
  $this-&gt;_em-&gt;flush($comment);
  </code></pre>
  
  <p>Now the result is false. It throws an exception and says <code>SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "page_id" violates not-null constraint</code>.</p>
  
  <p>Well, <strong>if i remove the oneToMany and ManyToOne relations, it works!</strong> If i use them it says it is null even if i give it...</p>
  
  <p>Where is my mistake? Any help or idea is appreciated!</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>I found this method: <code>getReference()</code></p>
  
  <pre><code>$item = $em-&gt;getReference('MyProject\Model\Item', $itemId);
  $cart-&gt;setPage($item);
  </code></pre>
  
  <p>Now it is <strong>working</strong> but i do not know if this is the correct way. Please inlight me.</p>
  
  <p>Basically, i want to <strong>add</strong> a comment <strong>without</strong> modifying (not remove nor update) the page table. But, i want to fetch them together as ManyToOne and OneToMany.</p>