DDC-1223: STI Inheritance Mapping Exception suggests to mark Entity abstract when initialization is not required, how to realize this? #1831

Closed
doctrinebot opened this Issue Jun 22, 2011 · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user holtkamp:

I have an abstract PHP class 'PartyAbstract' that uses Single Table Inheritance with a discriminator map to distinguish between a number of classes that extend the 'PartyAbstract' class. The 'PartyAbstract' class itself is not an entry in that discriminator map. Annotations are used to define the discriminator map.

/****
* @Entity
* @Table(schema="public", name="party")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discriminator", type="integer")
* @DiscriminatorMap({
* "1" = "Project\Entity\Party\PartyType1",
* "2" = "Project\Entity\Party\PartyType2",
* "3" = "Project\Entity\Party\PartyType3"
* })
abstract class PartyAbstract{}

As of version 2.1.0-rc1, the following exception is thrown:

"Entity 'Project\Entity\PartyAbstract' has to be part of the descriminator map of 'Project\Entity\PartyAbstract' to be properly mapped in the inheritance hierachy. If you want to avoid instantiation of this type mark it abstract."

My question is: how can I mark this Entity abstract? I DO want to be able to count the complete number of Parties, but instantiation of the PartyAbstract class is never required. The use of @MappedSuperclass is not allowed here, or together with the @Entity annotation...

PS: also not that the message in the exception contains two typo's

  • 'descriminator' vs 'discriminator'
  • 'hierachy' vs 'hierarchy'
@doctrinebot

Comment created by @beberlei:

This way:

/****
* @Entity
* @Table(schema="public", name="party")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discriminator", type="integer")
* @DiscriminatorMap({
* "0" = "Project\Entity\Party\PartyAbstract",
* "1" = "Project\Entity\Party\PartyType1",
* "2" = "Project\Entity\Party\PartyType2",
* "3" = "Project\Entity\Party\PartyType3"
* })
@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by holtkamp:

Aah, ok, that was the way I 'resolved' it, but the exception message confused me as it suggests that it requires a configuration setting to 'mark it abstract'. Maybe the following message can avoid this confusion:

"Entity 'Project\Entity\PartyAbstract' has to be part of the discriminator map of 'Project\Entity\PartyAbstract' to be properly mapped in the inheritance hierarchy. If you want to avoid instantiation of this type, make it an abstract class"

Thanks for the swift response!

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment