0

I have a new problem related to Doctrine2 and Oracle...

I migrated an application from Symfony1 to symfony2. When I insert a new entry in the production database with Doctrine2, I get the error "ORA-00001: unique constraint violated". It tries to insert with the ID 1, if I try again it tries to insert with ID 2 etc...

Here is how I setup my entity :

 <?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; } } 

Here is the code of the controller :

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())); } 

How do I configure Doctrine2 to get the last ID and not just increment from 1 ? Or should I get and insert the last ID manually ?

Regards

15
  • Did you update your schema? Commented May 2, 2014 at 9:15
  • Yes I did : "php app/console doctrine:schema:update --force" Commented May 2, 2014 at 9:23
  • I also have the following error when I try to validate the schema : [Mapping] OK - The mapping files are correct. [Database] FAIL - The database schema is not in sync with the current mapping file. Even if I do a update --dump-sql before stackoverflow.com/questions/13670471/… Commented May 2, 2014 at 9:31
  • And what is output of schema update force? Commented May 2, 2014 at 9:33
  • Updating database schema... Database schema updated successfully! "8" queries were executed Commented May 2, 2014 at 9:34

1 Answer 1

1

I found the solution to my problem. Apparently my SEQUENCES in Oracle were not up to date, so I had to manually update them.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.