Attempts to change readonly Id when generation strategy is NONE #6912

Open
opened 2026-01-22 15:41:13 +01:00 by admin · 2 comments
Owner

Originally created by @theMadness on GitHub (Jan 24, 2022).

Bug Report

Q A
BC Break no
Version 2.11.0

Summary

When persisting an entity with a NONE generation strategy and a readonly id property, a Logic Exception is thrown due to attempts to change the id value.

Current behavior

LogicException is thrown.

The last parts of the stack are
UnitOfWork->persistNew
ClassMetadataInfo->setIdentifierValues
ReflectionReadonlyProperty->setValue

How to reproduce

Attempt to persist an entity with a readonly (as in public readonly int $id) id without any GeneratedValue strategy.

Expected behavior

Normally persisted entity.

Originally created by @theMadness on GitHub (Jan 24, 2022). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.11.0 #### Summary When persisting an entity with a NONE generation strategy and a readonly id property, a Logic Exception is thrown due to attempts to change the id value. #### Current behavior LogicException is thrown. The last parts of the stack are UnitOfWork->persistNew ClassMetadataInfo->setIdentifierValues ReflectionReadonlyProperty->setValue #### How to reproduce Attempt to persist an entity with a readonly (as in public readonly int $id) id without any GeneratedValue strategy. #### Expected behavior Normally persisted entity.
admin added the Bug label 2026-01-22 15:41:13 +01:00
Author
Owner

@beberlei commented on GitHub (Jan 24, 2022):

This can't really be, when you use the "NONE" identify generator, then persistNew does not call setIdentifierValues:

6d5da83c68/lib/Doctrine/ORM/UnitOfWork.php (L991)

Could you investiagte a little more? Post the mapping exception message and the full stack trace please

@beberlei commented on GitHub (Jan 24, 2022): This can't really be, when you use the "NONE" identify generator, then `persistNew` does not call `setIdentifierValues`: https://github.com/doctrine/orm/blob/6d5da83c68c1e1dcb408290cc7bc6f485c0a156f/lib/Doctrine/ORM/UnitOfWork.php#L991 Could you investiagte a little more? Post the mapping exception message and the full stack trace please
Author
Owner

@theMadness commented on GitHub (Jan 24, 2022):

This can't really be, when you use the "NONE" identify generator, then persistNew does not call setIdentifierValues:

6d5da83c68/lib/Doctrine/ORM/UnitOfWork.php (L991)

Could you investiagte a little more? Post the mapping exception message and the full stack trace please

Will do as soon as I can, thank you for the very quick reply.

@theMadness commented on GitHub (Jan 24, 2022): > This can't really be, when you use the "NONE" identify generator, then `persistNew` does not call `setIdentifierValues`: > > https://github.com/doctrine/orm/blob/6d5da83c68c1e1dcb408290cc7bc6f485c0a156f/lib/Doctrine/ORM/UnitOfWork.php#L991 > > Could you investiagte a little more? Post the mapping exception message and the full stack trace please Will do as soon as I can, thank you for the very quick reply.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6912