Single id is not allowed on composite primary key in entity #5451

Closed
opened 2026-01-22 15:08:04 +01:00 by admin · 5 comments
Owner

Originally created by @podorozhny on GitHub (Mar 13, 2017).

Originally assigned to: @Ocramius on GitHub.

I have same issue as described in this question.

Can't use composite keys in entity, while having one of them being auto-generated.

For example:

/**
 * @Entity
 */
class User
{
    /**
      * @Id
      * @Column(type="integer")
      */
    private $foo;

    /**
      * @Id
      * @Column(type="integer")
      */
    private $bar;
}

This will work until I add @GeneratedValue() on one of them.

Thanks.

Originally created by @podorozhny on GitHub (Mar 13, 2017). Originally assigned to: @Ocramius on GitHub. I have same issue as described in this [question](http://stackoverflow.com/questions/39099801/symfony-3-doctrine-composite-key-single-id-is-not-allowed-on-composite-primary). Can't use composite keys in entity, while having one of them being auto-generated. For example: ``` /** * @Entity */ class User { /** * @Id * @Column(type="integer") */ private $foo; /** * @Id * @Column(type="integer") */ private $bar; } ``` This will work until I add @GeneratedValue() on one of them. Thanks.
admin added the ImprovementWon't FixCan't FixQuestion labels 2026-01-22 15:08:04 +01:00
admin closed this issue 2026-01-22 15:08:05 +01:00
Author
Owner

@Ocramius commented on GitHub (Mar 13, 2017):

Multi-column composite identifiers are not supported, and are going to stay like that for a while, since we didn't figure out how to properly handle them. A custom identifier generator strategy would be preferrable on your side.

Closing as won't fix

@Ocramius commented on GitHub (Mar 13, 2017): Multi-column composite identifiers are not supported, and are going to stay like that for a while, since we didn't figure out how to properly handle them. A custom identifier generator strategy would be preferrable on your side. Closing as `won't fix`
Author
Owner

@adrienbrault commented on GitHub (Jan 25, 2018):

@Ocramius Could you explain what the issue/limitation is ?

@adrienbrault commented on GitHub (Jan 25, 2018): @Ocramius Could you explain what the issue/limitation is ?
Author
Owner

@Ocramius commented on GitHub (Jan 25, 2018):

The problem is that the UnitOfWork and many other internal components assume that an identifier is either generated or not: we don't have a concept in between. I know @guilhermeblanco did some work on this for 3.x, but I don't know how far he got.

@Ocramius commented on GitHub (Jan 25, 2018): The problem is that the `UnitOfWork` and many other internal components assume that an identifier is either generated or not: we don't have a concept in between. I know @guilhermeblanco did some work on this for 3.x, but I don't know how far he got.
Author
Owner

@marquez20 commented on GitHub (Apr 4, 2020):

You need to remove all @Id in properties description except protected $id.

@marquez20 commented on GitHub (Apr 4, 2020): You need to remove all @Id in properties description except protected $id.
Author
Owner

@iamkhusainov7 commented on GitHub (Sep 24, 2023):

Multi-column composite identifiers are not supported, and are going to stay like that for a while, since we didn't figure out how to properly handle them. A custom identifier generator strategy would be preferrable on your side.

Closing as won't fix

There is a disadvantage of it. Like, JoinColumn referencedColumn key must always reference the entity identifier. For instance, I cannot use uuid as a foreign key if uuid is not the primary key.

@iamkhusainov7 commented on GitHub (Sep 24, 2023): > Multi-column composite identifiers are not supported, and are going to stay like that for a while, since we didn't figure out how to properly handle them. A custom identifier generator strategy would be preferrable on your side. > > Closing as `won't fix` There is a disadvantage of it. Like, JoinColumn referencedColumn key must always reference the entity identifier. For instance, I cannot use uuid as a foreign key if uuid is not the primary key.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5451