title: Doctrine 2 @joincolumns
body: <p>I have two entities Page and File. One Page has many Files. My other entities also have many Files, so I join Page and File by two columns (entity_id and entity_type). When I have sample data and I get it, everything work ok. I found problem when I tried to add Page and Files to db, Files get ID from Page but dont'get entity_type.</p>
  
  <p>Creating entities:</p>
  
  <pre><code> $page = new \CmsIr\Page\Entity\Page();
   $page-&gt;exchangeArray($form-&gt;getData());
   $page-&gt;setEntityType('page');
  
   $this-&gt;getEm()-&gt;persist($page);
   $this-&gt;getEm()-&gt;flush();
  
   foreach($scannedDirectory as $file) {
       $mimeType = $this-&gt;getFileService()-&gt;getMimeContentType($this-&gt;uploadDir . '/' . $file);
  
       $pageFile = new \CmsIr\File\Entity\File();
       $pageFile-&gt;setFilename($file);
       $pageFile-&gt;setPage($page);
       $pageFile-&gt;setMimeType($mimeType);
  
       $this-&gt;getEm()-&gt;persist($pageFile);
       $this-&gt;getEm()-&gt;flush();                       
   }
  </code></pre>
  
  <p>Error looks like:</p>
  
  <pre><code>An exception occurred while executing 'INSERT INTO cms_file (entity_type, entity_id, filename, mime_type) VALUES (?, ?, ?, ?)' with params [null, 5, "140343_las-promienie-slonca-56c9a66d27830.jpg", "image\/jpeg; charset=binary"]:
  
  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entity_type' cannot be null
  </code></pre>
  
  <p>Page:</p>
  
  <pre><code>/**
  * @ORM\Entity
  * @ORM\Table(name="cms_page")
  */
  class Page
  {
  /**
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   * @ORM\Column(type="integer")
   */
  protected $id;
  
  /** @ORM\Column(type="string") */
  protected $name;
  
  /** @ORM\Column(type="string") */
  protected $subtitle;
  
  /** @ORM\Column(type="string") */
  protected $url;
  
  /** @ORM\Column(type="string") */
  protected $entity_type;
  
  /**
  *  @ORM\OneToOne(targetEntity="CmsIr\System\Entity\Status")
  *  @ORM\JoinColumn(name="status_id", referencedColumnName="id")
  */
  protected $status;
  
  /** @ORM\Column(type="text") */
  protected $content;
  
  /** @ORM\Column(type="string") */
  protected $filename;
  
  /**
   * @ORM\OneToMany(targetEntity="CmsIr\File\Entity\File", mappedBy="page")
   */
  protected $files;
  
  public function __construct()
  {
      $this-&gt;files = new \Doctrine\Common\Collections\ArrayCollection();
  }
  </code></pre>
  
  <p>File:</p>
  
  <pre><code>/**
  * @ORM\Entity
  * @ORM\Table(name="cms_file")
  */
  class File
  {
  /**
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   * @ORM\Column(type="integer")
   */
  protected $id;
  
  /** @ORM\Column(type="string") */
  protected $entity_type;
  
  /** @ORM\Column(type="integer") */
  protected $entity_id;
  
  /** @ORM\Column(type="text") */
  protected $filename;
  
  /** @ORM\Column(type="string") */
  protected $mime_type;
  
  /**
   * @ORM\ManyToOne(targetEntity="CmsIr\Page\Entity\Page")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="entity_id", referencedColumnName="id"),
   *   @ORM\JoinColumn(name="entity_type", referencedColumnName="entity_type"),
   * })
  **/
  protected $page;
  </code></pre>