简体   繁体   中英

Single id is not allowed on composite primary key in entity AdminBundle\Entity\Comptable

I created a simple entity with primary key id and when I try to generate my entity, I get this error:

[Doctrine\ORM\Mapping\MappingException] Single id is not allowed on composite primary key in entity AdminBundle\Entity\Comptable

Here is the entity that contains some fields and the id value that I already created it in the database:

<?php

namespace AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Comptable
 *
 * @ORM\Table(name="comptable")
 * @ORM\Entity
 */
class Comptable
{

     /**
     * @var integer
     * 
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * @var float
     *
     * @ORM\Column(name="salaire", type="float", precision=10, scale=0, nullable=true)
     */
    private $salaire;

    /**
     * @var \AdminBundle\Entity\Personne
     *
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     * @ORM\OneToOne(targetEntity="AdminBundle\Entity\Personne")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Per_id", referencedColumnName="id")
     * })
     */
    private $per;
public  function __toString()
{
return $this->per->getPrenom().' '.$this->per->getNom();}


    /**
     * Set id
     *
     * @param integer $id
     *
     * @return Comptable
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

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

    /**
     * Set salaire
     *
     * @param float $salaire
     *
     * @return Comptable
     */
    public function setSalaire($salaire)
    {
        $this->salaire = $salaire;

        return $this;
    }

    /**
     * Get salaire
     *
     * @return float
     */
    public function getSalaire()
    {
        return $this->salaire;
    }

    /**
     * Set per
     *
     * @param \AdminBundle\Entity\Personne $per
     *
     * @return Comptable
     */
    public function setPer(\AdminBundle\Entity\Personne $per)
    {
        $this->per = $per;

        return $this;
    }

    /**
     * Get per
     *
     * @return \AdminBundle\Entity\Personne
     */
    public function getPer()
    {`enter code here`
        return $this->per;
    }
}

Remove the "@ORM\Id" from the "private $per;". Multicolumn composite identifiers are not supported.

/**
 * @var \AdminBundle\Entity\Personne
 *
 * @ORM\Id  <=== REMOVE THIS 
 * @ORM\GeneratedValue(strategy="NONE")
 * @ORM\OneToOne(targetEntity="AdminBundle\Entity\Personne")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="Per_id", referencedColumnName="id")
 * })
 */
 private $per;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM