Single id is not allowed on composite primary key in entity AdminBundleEntityComptable

Single id is not allowed on composite primary key in entity AdminBundleEntityComptable

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

[DoctrineORMMappingMappingException] Single id is not allowed on composite primary key in entity AdminBundleEntityComptable

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

<?php

namespace AdminBundleEntity;

use DoctrineORMMapping as ORM;

/**
 * Comptable
 *
 * @ORMTable(name="comptable")
 * @ORMEntity
 */
class Comptable
{

     /**
     * @var integer
     * 
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;


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

    /**
     * @var AdminBundleEntityPersonne
     *
     * @ORMId
     * @ORMGeneratedValue(strategy="NONE")
     * @ORMOneToOne(targetEntity="AdminBundleEntityPersonne")
     * @ORMJoinColumns({
     *   @ORMJoinColumn(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 AdminBundleEntityPersonne $per
     *
     * @return Comptable
     */
    public function setPer(AdminBundleEntityPersonne $per)
    {
        $this->per = $per;

        return $this;
    }

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

Source: Symfony Questions

Leave a Reply

Your email address will not be published. Required fields are marked *