我在 oracle 中使用学说 2,数据库中的表有一些生成 ID 的触发器,我的表的 ID 映射如下:
/**
* @orm\Id
* @orm\Column(type="integer");
* @orm\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
我有一个 OneToMany 关系,cascade={"persist"}
但它不起作用,我用 MySQL 尝试了相同的代码,它工作正常,但在 oracle 中,最后一个插入 ID 似乎总是返回 0 而不是插入行的真实 ID。 .所以级联持续不工作......这是教义中的错误还是我做错了什么?有什么帮助吗?
遵循代码后,该方法似乎
Doctrine\ORM\Id\IdentityGenerator::generate
返回0,我不知道为什么会调用它,因为它sequenceName
是null(定义中没有序列!
编辑:这里是实体: 客户实体:
/**
* @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;
}
}