'Symfony Doctrine - create new Entity dose not return the correct index

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



Solution 1:[1]

... 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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sitox