title: Symfony2 / Doctrine mapped superclass in the middle of class table inheritance
body: <p>I currently have a model structure as follows:</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\InheritanceType("JOINED")
   * @ORM\DiscriminatorColumn(name="related_type", type="string")
   * @ORM\DiscriminatorMap({"type_one"="TypeOne", "type_two"="TypeTwo"})
   */
  abstract class BaseEntity {
  
      ... (all the usual stuff, IDs, etc)
  
      /**
       * @ORM\OneToMany(targetEntity="Comment", mappedBy="baseEntity")
       */
      private $comments;
  }
  
  /**
   * @ORM\Entity
   */
  class TypeOne extends BaseEntity {
      /**
       * @ORM\Column(type="string")
       */
      private $name;
  
      /**
       * @ORM\Column(type="string")
       */
      private $description;
  }
  
  /**
   * @ORM\Entity
   */
  class TypeTwo extends BaseEntity {
      /**
       * @ORM\Column(type="string")
       */
      private $name;
  
      /**
       * @ORM\Column(type="string")
       */
      private $description;   
  }
  
  /**
   * @ORM\Entity
   */
  class Comment {
  
      ... (all the usual stuff, IDs, etc)
  
      /**
       * @ORM\ManyToOne(targetEntity="BaseEntity", inversedBy="comments")
       */
      private $baseEntity;
  }
  </code></pre>
  
  <p>The idea here is to be able to tie a comment to any of the other tables. This all seems to be working ok so far (granted, I'm still exploring design options so there could be a better way to do this...), but the one thing I've noticed is that the subclasses have some common fields that I'd like to move into a common parent class. I don't want to move them up into the BaseEntity as there will be other objects that are children of BaseEntity, but that won't have those fields.</p>
  
  <p>I've considered creating a MappedSuperclass parent class in the middle, like so:</p>
  
  <pre><code>/**
   * @ORM\MappedSuperclass
   */
  abstract class Common extends BaseEntity {
      /**
       * @ORM\Column(type="string")
       */
      private $name;
  
      /**
       * @ORM\Column(type="string")
       */
      private $description;       
  }
  
  /**
   * @ORM\Entity
   */
  class TypeOne extends Common {}
  
  /**
   * @ORM\Entity
   */
  class TypeTwo extends Common {}
  </code></pre>
  
  <p>I figured this would work, but the doctrine database schema generator is complaining that I can't have a OneToMany mapping on a MappedSuperclass. I didn't expect this to be a problem as the OneToMany mapping is still between the root BaseEntity and the Comment table. Is there a different structure I should be using, or other way to make these fields common without adding them on the BaseEntity?</p>