我在oracle中使用doctrine 2,數據庫中的表有一些生成ID的觸發器,我的表的ID映射像以下:Doctrine 2:cascade persist Oracle「IDENTITY」返回0作爲最後插入的ID
/**
* @orm\Id
* @orm\Column(type="integer");
* @orm\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
,我有一個一對多的關係,與cascade={"persist"}
但它不工作,我試圖與MySQL相同的代碼,它工作正常,但在甲骨文的最後插入標識似乎總是返回0,而不是插入行的真實ID ...所以級聯堅持不工作......這是一個教條的錯誤還是我做錯了什麼?任何幫助?
下面的代碼後,它似乎方法
Doctrine\ORM\Id\IdentityGenerator::generate
將返回0,我不知道爲什麼被調用它,因爲sequenceName
爲空(沒有在deffinition沒有序列!
編輯:這裏是實體: 客戶實體:
/**
* @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 as $contactInformation) {
$contactInformation->setClient($this);
$this->contactInformations->add($contactInformation);
}
}
/**
* @param Collection $tags
*/
public function removeContactInformations(Collection $contactInformations)
{
foreach ($contactInformations as $contactInformation) {
$contactInformation->setClient(null);
$this->contactInformations->removeElement($contactInformation);
}
}
public function setContactInformations($contactInformations) {
$this->contactInformations = $contactInformations;
return $this;
}
}
聯絡信息實體:
/**
* @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;
}
}
你能告訴我們兩個實體的代碼(特別是映射)嗎? –
@Jasper我只是在問題中添加了實體... –