【发布时间】:2020-04-11 00:16:14
【问题描述】:
我在 Symfony 4 中使用教义/oracle/oci8 驱动程序向数据库插入新记录时遇到问题。 我的带有序列 ID 生成的实体配置:
<id name="id" type="integer" column="ID">
<generator strategy="SEQUENCE"/>
<sequence-generator sequence-name="FILES_SEQ" allocation-size="10" initial-value="1"/>
</id>
这就是我向数据库中插入新记录的方式:
$file = new File();
$file->setFileName($fileParams['fileName']);
...
$this->getEntityManager()->persist($file);
$this->getEntityManager()->flush();
记录已成功保存,但问题是当我尝试通过以下方式获取最后插入 ID 时:
$file->getId();
那么返回的 ID 比数据库中的 1 少 1。这是某种缓存问题吗?我尝试使用 getEntityManager()->refresh($file) 但它不起作用。 另外,当我调用 findAll() 方法时,那里的 ID 值是正确的。
【问题讨论】: