doctrine2 - Doctrine 2: cascade persist Oracle "IDENTITY" is returning 0 as last inserted ID -


i using doctrine 2 oracle, tables in database has triggers generate ids, , id mapping of tables following:

/**  * @orm\id  * @orm\column(type="integer");  * @orm\generatedvalue(strategy="identity")  */ protected $id; 

and have onetomany relation, cascade={"persist"} not working, tried same code mysql , working fine, in oracle last insert id seems return 0 instead of real id of inserted row... , cascade persist not working... bug in doctrine or doing wrong? help?

after following code seems method

doctrine\orm\id\identitygenerator::generate

is returning 0, don't know why being invoked since sequencename null (there no sequence in deffinition!

edit: here entities: client entity:

/**   * @orm\entity   * @orm\table(name="clients")  **/ class client {     /**      * @orm\id      * @orm\generatedvalue(strategy="identity")      * @orm\column(type="integer")      */     protected $id;      /** @orm\column(name="name",type="string",length=255,unique=true) */     protected $name;      /**     * @orm\onetomany(targetentity="contactinformation", mappedby="client", cascade={"persist"})     **/     protected $contactinformations;      public function __construct() {         $this->contactinformations = new arraycollection();     }      public function getid() {         return $this->id;     }      public function getname() {         return $this->name;     }      public function setname($name) {         $this->name = $name;         return $this;     }      public function getcontactinformations() {         return $this->contactinformations;     }      public function addcontactinformations(collection $contactinformations)     {         foreach ($contactinformations $contactinformation) {             $contactinformation->setclient($this);             $this->contactinformations->add($contactinformation);         }     }      /**      * @param collection $tags      */     public function removecontactinformations(collection $contactinformations)     {         foreach ($contactinformations $contactinformation) {             $contactinformation->setclient(null);             $this->contactinformations->removeelement($contactinformation);         }     }      public function setcontactinformations($contactinformations) {         $this->contactinformations = $contactinformations;         return $this;     } } 

the contact information entity:

/**   * @orm\entity   * @orm\table(name="contact_informations")  **/ class contactinformation {     /**      * @orm\id      * @orm\generatedvalue(strategy="identity")      * @orm\column(type="integer")      */     protected $id;      /**      * @orm\onetoone(targetentity="contactinformationtype")      * @orm\joincolumn(name="type_id", referencedcolumnname="id")      **/     protected $type;      /** @orm\column(type="text") */     protected $value;      /**      * @orm\manytoone(targetentity="client", inversedby="contact_informations")      * @orm\joincolumn(name="client_id", referencedcolumnname="id")      **/     private $client;      public function getid() {         return $this->id;     }      public function gettype() {         return $this->type;     }      public function settype($type) {         $this->type = $type;         return $this;     }      public function getvalue() {         return $this->value;     }      public function setvalue($value) {         $this->value = $value;         return $this;     }      public function getclient() {         return $this->client;     }      public function setclient($client = null) {         $this->client = $client;         return $this;     } } 

oracle doesn't support auto incrementing, cannot use "identity" strategy in doctrine. you'll have use "sequence" (or "auto") strategy.

when specifying "auto", doctrine use "identity" mysql , "sequence" oracle.

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifier-generation-strategies


Comments