title: Doctrine 2 mapping: 2 fields for the 1 database column
body: <p>I want to have an alternative approach of the relationship referencing for each my Doctrine 2 entity: each entity relationship can be instantiated via <strong>id field</strong> or via <strong>reference field</strong>, and both fields mapped to the same database column.</p>
  
  <p>Let me show:</p>
  
  <pre><code>/**
   * @var integer
   *
   * @Column(name = "REF_ID", type = "integer", nullable = false)
   */
  private $refId;
  
  /**
   * @var IBlock
   *
   * @ManyToOne(targetEntity = "Ref")
   * @JoinColumn(name = "REF_ID", referencedColumnName = "ID")
   */
  private $ref;
  </code></pre>
  
  <p>Whet I call persist for the such entity:</p>
  
  <pre><code> $entity = new Entity();
   $entity-&gt;setName("Test entity");
   $entity-&gt;setRefId(14);
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>Column 'REF_ID' cannot be null
  </code></pre>
  
  <p>How can I implement workaround this? Is there any way to fix it?</p>
  
  <p>Thanks!</p>