Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 464
user2090861 Avatar asked Oct 16 '13 16:10

user2090861


1 Answers

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 !

like image 100
user2090861 Avatar answered Nov 08 '22 23:11

user2090861