mirror of
https://github.com/doctrine/orm.git
synced 2026-04-29 09:23:20 +02:00
Rework sequence-based identity generation #6791
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @morozov on GitHub (Jul 18, 2021).
Originally assigned to: @greg0ire on GitHub.
Sequence-based identity values will be deprecated in DBAL
3.2.0(https://github.com/doctrine/dbal/pull/4688) and removed in4.0.x(https://github.com/doctrine/dbal/pull/4691). See the details in https://github.com/doctrine/dbal/issues/4687.The ORM currently uses this API: https://github.com/doctrine/orm/blob/f3e55fae9fdbdbc23897006bdbf016c20e11f6e9/lib/Doctrine/ORM/Id/IdentityGenerator.php#L52-L55
Please consider not relying on this API.
@greg0ire commented on GitHub (Aug 21, 2021):
@beberlei I think this should go in a "DBAL 4" support project, shouldn't it? 😄
@morozov commented on GitHub (Aug 21, 2021):
In fact, this functionality in the ORM could be salvaged, if necessary. I updated the subject and the description.
The DBAL doesn't support using sequence values to implement
lastInsertId()because it's not thread-safe but the sequences themselves are. The ORM could generate the identity value using a sequence explicitly and pass to theINSERTw/o relying on thelastInsertId()API in the same way as it does with UUIDs, for example:In this case, the ORM should not declare the column as
autoincrementand should own the sequence, unlike the current implementation when the DBAL owns it.It is also possible to leave the sequence ownership to the DBAL and have the column always auto-incremented via a trigger. In this case, the ORM should use a query like:
And then use an out parameter to get the id.
@stof commented on GitHub (Dec 4, 2021):
This is about using a SequenceGenerator instead of a IdentityGenerator then (as that's what the SequenceGenerator does)
@stof commented on GitHub (Dec 4, 2021):
I suggest instead deprecating the support for sequence-based IdentityGenerator, so that projects using a platform that does not support identity columns have to use something else (for instance the SequenceGenerator)
@onurkose commented on GitHub (Aug 30, 2023):
Hello, today I changed the id columns' strategy from IDENTITY to SEQUENCE in my entities after reading the deprecation messages, and now all the insert statements have
nullid field values if the entity is using JOINED type entity inheritance.setIdentifierValuesmethod ofClassMetadataInfoclass sets the new ids to reflection class, but then it turns intonullsomehow.