MySQL 5.7 JSON ordering affects change computation #5946

Open
opened 2026-01-22 15:22:53 +01:00 by admin · 0 comments
Owner

Originally created by @MisatoTremor on GitHub (Apr 10, 2018).

Originally assigned to: @Ocramius on GitHub.

This is not really an issue with ORM itself, but can happen in conjunction with DBAL and MySQL 5.7s JSON type

If you store an associative array as a object property which, due to processing, is always ordered before persisting (e.g. ["baz" => "bar", "foo" => "bar"]) it will be correctly processed by JsonType::convertToDatabaseValue into
{"baz": "bar", "foo": "bar"}
But due to MySQLs JSON normalization might end up in the database as
{"foo": "bar", "baz": "bar"}.
So when hydrating the object the UOW will store this as value in the original entity data and when computing changes later will detect it as change.

Originally created by @MisatoTremor on GitHub (Apr 10, 2018). Originally assigned to: @Ocramius on GitHub. This is not really an issue with ORM itself, but can happen in conjunction with DBAL and MySQL 5.7s JSON type If you store an associative array as a object property which, due to processing, is always ordered before persisting (e.g. ``["baz" => "bar", "foo" => "bar"]``) it will be correctly processed by ``JsonType::convertToDatabaseValue`` into ``{"baz": "bar", "foo": "bar"}`` But due to MySQLs [JSON normalization](https://dev.mysql.com/doc/refman/5.7/en/json.html#json-normalization) might end up in the database as ``{"foo": "bar", "baz": "bar"}``. So when hydrating the object the UOW will store this as value in the original entity data and when computing changes later will detect it as change.
admin added the BugCan't Fix labels 2026-01-22 15:22:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5946