title: Doctrine Many to Many join error
body: <p>I am trying to create a many to many join from the products to categories tables in ZF2 using Doctrine 2.</p>
  
  <p>In my categories entity I have</p>
  
  <pre><code>/**
       * @var \Doctrine\ORM\PersistentCollection
       * 
       * @ORM\ManyToMany(targetEntity="Application\Entity\Products", inversedBy="categories")
       * @ORM\JoinTable(name="product_to_category",
       *      joinColumns={@ORM\joinColumn(name="category_id", referencedColumnName="category_id")},
       *      inverseJoinColumns={@ORM\joinColumn(name="product_id", referencedColumnName="product_id")}
       * )
       */
      private $products;
  </code></pre>
  
  <p>and in my products entity I have</p>
  
  <pre><code>/**
       * @var Doctrine\ORM\PersistentCollection
       *
       * @ORM\ManyToMany(targetEntity="Application\Entity\Categories", mappedBy="products")
       */
      private $categories;
  </code></pre>
  
  <p>But i keep getting the error <strong>Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'The column category_id must be mapped to a field in class Application\Entity\Categories since it is referenced by a join column of another class.' in C:\Users\User\Documents\My Webs\freedomsnew\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\MappingException.php on line 328</strong> when I try to lazy load the data.</p>
  
  <p>I'm not sure what the error is trying to tell me and I cant see anything wrong!!</p>
  
  <p>Please can someone point me in the right direction.</p>
  
  <p>Many thanks in advance.</p>