Multiple CTI (Class Inheritance) among classes in Doctrine 2?

I want to have the following hierarchy in Doctrine2:

- Message - SMS - SentSMS - ScheduledSMS - FailedSMS - Newsletter - SystemComunication 

But when I try to generate objects in Symfony 2, I get the following error:

[Teaching \ ORM \ Mappin \ MappingException]
Entity 'Acme \ HelloBundle \ Entity \ FailedSMS' has a composite identifier but uses an ID generator other than the manual assignment (Identity, Sequence). This is not supported.

I think that because the id of FailedSMS (inherited from Message ), it contradicts the fact that FailedSMS itself must have an assigned id for CTI (with SMS ) before it works.

Am I asking the moon, or is there a way to make it work? A small overview of the hierarchy:

 /** * @ORM\Entity * @ORM\Table(name="message") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap({"newsletter" = "Newsletter", "sms" = "SMS"}) */ class Message {} /** * @ORM\Entity * @ORM\Table(name="newsletter") */ class Newsletter extends Message {} /** * @ORM\Entity * @ORM\Table(name="sms") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="status", type="string") * @ORM\DiscriminatorMap({"sent"="SentSMS", "scheduled"="ScheduledSMS", * "failed"="FailedSMS" * }) */ class SMS extends Message {} /** * @ORM\Entity * @ORM\Table(name="failed_sms") */ class FailedSMS extends SMS {} 
+7
source share
1 answer

It seems to me that you really do not need a "message" table. If this is the case, you should define the message as a mapped superclass

 <?php namespace Your\Bundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\MappedSuperClass * */ abstract class MappedSuperClassMessage { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Everything else you want the subclasses to have */ } 

Now only the CTI you need to configure is for SMS classes.

 /** * @ORM\Entity * @ORM\Table(name="newsletter") */ class Newsletter extends MappedSuperClassMessage {} /** * @ORM\Entity * @ORM\Table(name="sms") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="status", type="string") * @ORM\DiscriminatorMap({"sent"="SentSMS", "scheduled"="ScheduledSMS", * "failed"="FailedSMS" * }) */ class SMS extends MappedSuperClassMessage {} /** * @ORM\Entity * @ORM\Table(name="failed_sms") */ class FailedSMS extends SMS {} 

This is not a verified answer, so I'm not sure if you will have problems with it or not.

+3
source

All Articles