title: Store data in MongoDB and MySQL via Doctrine using the same Entity/Document-Class
body: <p>I need help. Here is the situation. I am using Symfony2 + FOSRestBundle, I created my Entity-Classes to store my data in MySQL via Doctrine. I also wrote all the Controllers to get the data and directly translate it to my database. That works fine.</p>
  
  <pre><code>namespace Stat\ContentBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  
  /** 
   * @ORM\Entity
   * @ORM\Table(name="agegroups")
   */
   class Table
   {
   * @ORM\Column(name="id", type="smallint")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
   protected $id;
  
   /**
   * @ORM\Column(name="description", type="string", length=50)
   * @Type("string")
   */
   protected $description;
  </code></pre>
  
  <p>Now I do want to use the same Entity declaration and extend it with some more information for usage with MongoDB. I want to store my data in MySQL and additionally in MongoDB. To reuse the code with the mongodb-odm-bundle I have to use the namespace Document - and that's just the beginning of the problems. If I would want to reuse my Controllers I would have to rewrite that code for MongoDB as well. </p>
  
  <pre><code>namespace Stat\ContentBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
  
  /** 
   * @MongoDB\Document
   * @ORM\Entity
   * @ORM\Table(name="agegroups")
   */
  
   class Table
   {
   * @ORM\Column(name="id", type="smallint")
   * @ORM\Id
   * @MongoDB\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
   protected $id;
  
   /**
   * @ORM\Column(name="description", type="string", length=50)
   * @MongoDB\String
   * @Type("string")
   */
   protected $description;
  
   /**
   * @ORM\Column(name="mySqlOnly", type="string", length=50)
   * @Type("string")
   */
   protected $mySqlOnly;
  
   /**
   * @MongoDB\String
   */
   protected $mongoDbOnly;    
  </code></pre>
  
  <p>Is there an easy way to use a Doctrine-database schema for both document-based and relational databases?</p>