Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework sequence-based identity generation #8850

Closed
morozov opened this issue Jul 18, 2021 · 5 comments
Closed

Rework sequence-based identity generation #8850

morozov opened this issue Jul 18, 2021 · 5 comments
Assignees

Comments

@morozov
Copy link
Member

morozov commented Jul 18, 2021

Sequence-based identity values will be deprecated in DBAL 3.2.0 (doctrine/dbal#4688) and removed in 4.0.x (doctrine/dbal#4691). See the details in doctrine/dbal#4687.

The ORM currently uses this API:

public function generate(EntityManager $em, $entity)
{
return (int) $em->getConnection()->lastInsertId($this->sequenceName);
}

Please consider not relying on this API.

@beberlei beberlei added this to To do in DBAL 3 support via automation Aug 5, 2021
@greg0ire
Copy link
Member

greg0ire commented Aug 21, 2021

@beberlei I think this should go in a "DBAL 4" support project, shouldn't it? 😄

@morozov
Copy link
Member Author

morozov commented 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 the INSERT w/o relying on the lastInsertId() API in the same way as it does with UUIDs, for example:

$id = $conn->execute('SELECT ' . $seqName . '.NEXTVAL FROM DUAL');
$conn->insert($table, ['id' => $id]);

In this case, the ORM should not declare the column as autoincrement and 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:

INSERT INTO table VALUES (...) RETURNING id INTO :id;

And then use an out parameter to get the id.

@morozov morozov changed the title Deprecate sequence-based identity generation Rework sequence-based identity generation Aug 21, 2021
@stof
Copy link
Member

stof commented Dec 4, 2021

This is about using a SequenceGenerator instead of a IdentityGenerator then (as that's what the SequenceGenerator does)

@stof
Copy link
Member

stof commented 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
Copy link

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 null id field values if the entity is using JOINED type entity inheritance.

setIdentifierValues method of ClassMetadataInfo class sets the new ids to reflection class, but then it turns into null somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

4 participants