Search code examples
phpsymfonydoctrine-orm

Symfony2: Duplicate definition of column 'id' on entity in a field or discriminator column mapping


I'm having trouble using entity inheritance in Symfony2. Here are my two classes:

use Doctrine\ORM\Mapping as ORM;

/**
 * @Orm\MappedSuperclass
 */
class Object
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
}


/**
  * @Orm\MappedSuperclass
 */
class Book extends Object
{
}

When I run php app/console doctrine:schema:create I get the following error:

[Doctrine\ORM\Mapping\MappingException]  
Duplicate definition of column 'id' on entity 'Name\SiteBundle\Entity\Book' in a field or discriminator column mapping.

What may be causing this?

Thanks :)

Update:

You are right I missed this. Now I'm using single table inheritance with both classes being entities:

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"object" = "Object", "book" = "Book"})
 */

But I still get the same error message.


Solution

  • Actually I found yml files in Resources/config/doctrine/, which were defining my entities, instead of just using annotations.

    I removed these files and it's working now.

    Thanks for your help !