Symfony Doctrine - 创建新实体不返回正确的索引
我的 symfony 项目中有以下实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Protocol
*
* @ORM\Table(name="PROTOCOL", indexes={@ORM\Index(name="IDX_DD646AFA5C1750A", columns={"EPT_ID"})})
* @ORM\Entity
*/
class Protocol
{
/**
* @var int
*
* @ORM\Column(name="PK_ID_PK", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $pkIdPk;
/**
* @var string|null
*
* @ORM\Column(name="PK_REC_NAME", type="string", length=255, nullable=true)
*/
private $pkRecName;
/**
* @var \ExProtocolTyp
*
* @ORM\ManyToOne(targetEntity="ExProtocolTyp")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="EPT_ID", referencedColumnName="EPT_ID")
* })
*/
private $ept;
public function getPkIdPk(): ?int
{
return $this->pkIdPk;
}
public function getPkRecName(): ?string
{
return $this->pkRecName;
}
public function setPkRecName(?string $pkRecName): self
{
$this->pkRecName = $pkRecName;
return $this;
}
public function getEpt(): ?ExProtocolTyp
{
return $this->ept;
}
public function setEpt(?ExProtocolTyp $ept): self
{
$this->ept = $ept;
return $this;
}
}
当我现在想要创建一个新实体时:
$dispProt = new Protocol();
$dispProt->setPkRecName($canProd['csRecipeName']);
$dispProt->setEpt($ept);
$this->em->persist($dispProt);
$this->em->flush();
// ####### show the new Index of the Entity #######
dd($this->em->getConnection()->lastInsertId());
例如,返回的索引是 1498。 这不是数据库中最新的最高索引。 最新的最高可用指数是 2495。1498 是免费指数,但不是最新的最高指数。
现在的问题是,之后数据库中的插入不在索引 1498 上,新记录集将使用索引 2495 插入。
有谁知道出了什么问题。为了使用,我需要插入记录集的索引,因此 2495。 我使用 MS SQl Server 作为数据库
I have the following Entity in my symfony project:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Protocol
*
* @ORM\Table(name="PROTOCOL", indexes={@ORM\Index(name="IDX_DD646AFA5C1750A", columns={"EPT_ID"})})
* @ORM\Entity
*/
class Protocol
{
/**
* @var int
*
* @ORM\Column(name="PK_ID_PK", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $pkIdPk;
/**
* @var string|null
*
* @ORM\Column(name="PK_REC_NAME", type="string", length=255, nullable=true)
*/
private $pkRecName;
/**
* @var \ExProtocolTyp
*
* @ORM\ManyToOne(targetEntity="ExProtocolTyp")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="EPT_ID", referencedColumnName="EPT_ID")
* })
*/
private $ept;
public function getPkIdPk(): ?int
{
return $this->pkIdPk;
}
public function getPkRecName(): ?string
{
return $this->pkRecName;
}
public function setPkRecName(?string $pkRecName): self
{
$this->pkRecName = $pkRecName;
return $this;
}
public function getEpt(): ?ExProtocolTyp
{
return $this->ept;
}
public function setEpt(?ExProtocolTyp $ept): self
{
$this->ept = $ept;
return $this;
}
}
When I now want to create a new entity with:
$dispProt = new Protocol();
$dispProt->setPkRecName($canProd['csRecipeName']);
$dispProt->setEpt($ept);
$this->em->persist($dispProt);
$this->em->flush();
// ####### show the new Index of the Entity #######
dd($this->em->getConnection()->lastInsertId());
The returned Index for example is 1498.
That is not the latest highest index in the Database.
The lastest highest usable index is 2495. The 1498 is a free Index but not the latest highest.
And now the Problem is that the insert in the Database after that is not on the index of 1498, the new recordset will be inserted with the idex 2495.
Did anyone know what's wrong. To work with I need the index on which the recordset was inserted, so the 2495.
I'm using the MS SQl Server as Database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
...好吧,我发现了问题。
这是我的协议表中的触发器。禁用它们后,我得到了 ORM 中返回的正确索引。
我不明白为什么触发器会导致这种效果。
... okay I found the problem.
It was a trigger in my Protcol-Table. After I disable them I get the right index returned in doctrine ORM.
I couldn't find out why that Trigger has causes this effect.