Php Symfony Doctrine2不';请不要插入可用的ID

Php Symfony Doctrine2不';请不要插入可用的ID,php,sql,oracle,symfony,doctrine-orm,Php,Sql,Oracle,Symfony,Doctrine Orm,我有一个与Doctrine2和Oracle相关的新问题 我将应用程序从Symfony1迁移到symfony2。当我使用Doctrine2在生产数据库中插入一个新条目时,会出现错误“ORA-00001:违反了唯一约束”。它尝试使用ID 1插入,如果我再次尝试,它将尝试使用ID 2插入,等等 以下是我如何设置实体: <?php namespace EspaceApprenti\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM;

我有一个与Doctrine2和Oracle相关的新问题

我将应用程序从Symfony1迁移到symfony2。当我使用Doctrine2在生产数据库中插入一个新条目时,会出现错误“ORA-00001:违反了唯一约束”。它尝试使用ID 1插入,如果我再次尝试,它将尝试使用ID 2插入,等等

以下是我如何设置实体:

    <?php

namespace EspaceApprenti\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * ApprenticeMark
 *
 * @ORM\Table(name="APPRENTICE_MARK", indexes={@ORM\Index(name="IDX_8582BCF7105754FC", columns={"FK_BRANCH"}), @ORM\Index(name="IDX_8582BCF7C9387C17", columns={"FK_YEAR"}), @ORM\Index(name="IDX_8582BCF73B451C64", columns={"FK_MARKTYPE"})})
 * @ORM\Entity(repositoryClass="EspaceApprenti\UserBundle\Entity\ApprenticeMarkRepository")
 */
class ApprenticeMark
{
    /**
     * @var integer
     *
     * @ORM\Column(name="COEFFICIENT", type="bigint", nullable=false)
     */
    private $coefficient;

    /**
     * @var integer
     *
     * @ORM\Column(name="ID", type="bigint", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="RESULT", type="decimal", precision=2, scale=1, nullable=false)
     */
    private $result;

    /**
     * @var \ApprenticeBranch
     *
     * @ORM\ManyToOne(targetEntity="ApprenticeBranch")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="FK_BRANCH", referencedColumnName="ID")
     * })
     */
    private $fkBranch;

    /**
     * @var \ApprenticeYear
     *
     * @ORM\ManyToOne(targetEntity="ApprenticeYear")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="FK_YEAR", referencedColumnName="ID", onDelete="CASCADE")
     * })
     */
    private $fkYear;

    /**
     * @var \ApprenticeMarktype
     *
     * @ORM\ManyToOne(targetEntity="ApprenticeMarktype")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="FK_MARKTYPE", referencedColumnName="ID")
     * })
     */
    private $fkMarktype;



    /**
     * Set coefficient
     *
     * @param integer $coefficient
     * @return ApprenticeMark
     */
    public function setCoefficient($coefficient)
    {
        $this->coefficient = $coefficient;

        return $this;
    }

    /**
     * Get coefficient
     *
     * @return integer 
     */
    public function getCoefficient()
    {
        return $this->coefficient;
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set result
     *
     * @param integer $result
     * @return ApprenticeMark
     */
    public function setResult($result)
    {
        $this->result = $result;

        return $this;
    }

    /**
     * Get result
     *
     * @return integer
     */
    public function getResult()
    {
        return $this->result;
    }

    /**
     * Set fkBranch
     *
     * @param \EspaceApprenti\UserBundle\Entity\ApprenticeBranch $fkBranch
     * @return ApprenticeMark
     */
    public function setFkBranch(\EspaceApprenti\UserBundle\Entity\ApprenticeBranch $fkBranch = null)
    {
        $this->fkBranch = $fkBranch;

        return $this;
    }

    /**
     * Get fkBranch
     *
     * @return \EspaceApprenti\UserBundle\Entity\ApprenticeBranch 
     */
    public function getFkBranch()
    {
        return $this->fkBranch;
    }

    /**
     * Set fkYear
     *
     * @param \EspaceApprenti\UserBundle\Entity\ApprenticeYear $fkYear
     * @return ApprenticeMark
     */
    public function setFkYear(\EspaceApprenti\UserBundle\Entity\ApprenticeYear $fkYear = null)
    {
        $this->fkYear = $fkYear;

        return $this;
    }

    /**
     * Get fkYear
     *
     * @return \EspaceApprenti\UserBundle\Entity\ApprenticeYear 
     */
    public function getFkYear()
    {
        return $this->fkYear;
    }

    /**
     * Set fkMarktype
     *
     * @param \EspaceApprenti\UserBundle\Entity\ApprenticeMarktype $fkMarktype
     * @return ApprenticeMark
     */
    public function setFkMarktype(\EspaceApprenti\UserBundle\Entity\ApprenticeMarktype $fkMarktype = null)
    {
        $this->fkMarktype = $fkMarktype;

        return $this;
    }

    /**
     * Get fkMarktype
     *
     * @return \EspaceApprenti\UserBundle\Entity\ApprenticeMarktype 
     */
    public function getFkMarktype()
    {
        return $this->fkMarktype;
    }
}
如何配置Doctrine2以获取最后一个ID,而不仅仅是从1开始递增? 还是应该手动获取并插入最后一个ID


我找到了解决问题的办法。显然,我在Oracle中的序列不是最新的,所以我必须手动更新它们。

您更新了架构吗?是的,我更新了:“php应用程序/控制台原则:架构:更新--force”我在尝试验证架构时也出现以下错误:[Mapping]确定-映射文件正确。[数据库]失败-数据库架构与当前映射文件不同步。即使我做了一个更新——之前转储sql,模式更新强制的输出是什么?更新数据库模式。。。数据库架构更新成功!执行了“8”个查询
public function newAction($idYear,$idYeartype)
    {
        $m = $this->getDoctrine()
                  ->getManager();

        // Get year
        $year = $m->getRepository('EspaceApprentiUserBundle:ApprenticeYear')->find($idYear);
        if (!$year) {
                throw $this->createNotFoundException('Year not found');
        }
        // Get yeartype
        $yeartype = $m->getRepository('EspaceApprentiUserBundle:ApprenticeYeartype')->find($idYeartype);
        if (!$yeartype) {
                throw $this->createNotFoundException('Year type not found');
        }
        // Get apprentice
        $apprentice = $m->getRepository('EspaceApprentiUserBundle:ApprenticeApprentice')->find($year->getFkApprentice()->getId());
        if (!$apprentice) {
                throw $this->createNotFoundException('Apprentice type not found');
        }

        $mark = new ApprenticeMark();
        $mark->setFkYear($year);
        $form = $this->createForm(new ApprenticeMarkType($yeartype), $mark);

        $request = $this->get('request');
        if ($request->getMethod() == 'POST') {
                $form->bind($request);
                if ($form->isValid()) {
                        $m->persist($mark);
                        $m->flush();
                        return $this->redirect($this->generateUrl('grids_apprentice_index',array('idApprentice' => $apprentice->getId())));
                }
        }

        return $this->render('EspaceApprentiGridsBundle:Grids_Mark:new.html.twig', array('apprentice' => $apprentice, 'form' => $form->createView()));
    }