Single id is not allowed on composite primary key in entity Doctrine error

Single id is not allowed on composite primary key in entity Doctrine error

You might get the above error on PHP Doctrine

if you got the above error, then it means you have two or more ids as primary in your object representing the table.

Example:

class Member
   /** @id 
    * @Column(type="integer") 
    * @GeneratedValue(strategy="AUTO")
    */
   private $id;
   /** @id @Column(type="string") */
   private $key;
...

The above declaration would create the above error and taking out the generatedValue part can resolve the issue.

See the solution to common error of new entity was found though relation while using doctrine

AbstractSureFireMojo Class Missing Maven Surefire

Spring Data error: getOutputStream() has already been called for this response

Post to Facebook From app – Using PHP

connect to sftp from php

No Persistence provider for EntityManager named Hibernate error

Java Tomcat error: can not access a member of class with modifiers

3 Comments
  1. Klaas

    Do you happen to know why below code still ends in: “Single id is not allowed on composite primary key”?

    /**
    * @ORMId
    * @ORMManyToOne(targetEntity=”Customer”)
    * @ORMJoinColumn(name=”TCUST”, referencedColumnName=”CCUST”)
    */
    private $customer;

    /**
    * @ORMId
    * @ORMColumn(name=”TSHIP”, type=”integer”)
    */
    private $tship;

    /**
    * @ORMColumn(name=”TCUST”, type=”integer”)
    */
    private $tcust;

    1. gullele

      Hello Klaas,
      it would be difficult to get the problem from the snippet you provided. It would help if you provided what ‘Customer’ would look like.
      Anyway, based on the error message, it looks the database has multiple primary key and if that is the case, you have to provide those keys you defined on the relation you are creating.

  2. teste07

    Perfect, thankyou!

Leave a Reply

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

*
*