Symfony 8.2 Cuts Doctrine Setup Across Entities, Dates and Messenger
- Javier Eguiluz
- 379 reads
Symfony 8.2 reduces Doctrine configuration and fixes collection handling, with entity discovery and DBAL middleware bringing the clearest workflow changes.

Symfony 8.2 trims several recurring bits of Doctrine setup: entity directories can be discovered automatically, DatePoint fields no longer need a repeated type declaration, and Messenger gains middleware that works directly with DBAL connections. The changes target different parts of an application, but share a practical aim: remove configuration or conversion steps that developers previously had to supply themselves.

For teams maintaining many entity directories or using DBAL without the ORM, the setup changes may matter most. The Serializer update is narrower, but it addresses a common mismatch between collection-typed objects and the plain arrays produced during deserialization. Each feature has version or configuration details to check before removing existing declarations.
Entity discovery follows Symfony’s service scan
Doctrine ORM needs to know where entities live. Applications typically provide mappings that name the directories and namespaces to scan. That becomes repetitive when a codebase divides entities across multiple areas, such as bounded contexts.

Symfony 8.2 adds a doctrine.orm.entity tag to scanned classes marked with #[Entity] or #[MappedSuperclass]. DoctrineBundle 3.4 uses those tags to register the entities, so an application can omit hand-written mappings when its entity manager has neither mappings nor auto_mapping configured.
The discovery mechanism builds on Symfony’s existing scan of the src/ directory, which has been used since Symfony 7.3 to find classes that should be excluded from the service container. The important implementation detail is that discovery depends on that scan. If services.yaml excludes an entity directory, such as ../src/Entity/, the classes there won’t be found until that exclusion is removed.

Existing configuration can remain. When an entity manager already uses mappings or auto_mapping—for example, to load entities supplied by bundles—set auto_discover_entities to true to enable discovery as well. Explicit mappings take precedence over discovered entities. The feature requires Doctrine ORM 3.6 or higher, so teams should check that dependency before expecting the new behavior.
DatePoint columns need less repeated metadata
The Symfony Clock component’s DatePoint class has a matching Doctrine bridge type, date_point, for database storage. Previously, Doctrine couldn’t infer that type from a property declared as DatePoint, so developers had to state it on each column. Symfony 8.2 removes that repetition: an ordinary #[ORM\Column] declaration is enough for a DatePoint property.

This works across entity managers. Applications with a custom typed field mapper in DoctrineBundle keep their existing precedence: Doctrine asks that mapper first. There’s also a boundary to the inference. The day_point and time_point types can store DatePoint objects too, but developers still need to specify those types explicitly.
That distinction matters when reviewing a schema mapping: the property type now identifies the general date_point column, while specialized storage choices still require a declaration. The change cuts boilerplate without making every possible database representation implicit.

Serializer preserves collection types
When Symfony’s Serializer denormalized data into an object with a Doctrine collection property, it could construct the collection’s elements correctly and then pass them to the object as a plain array. A constructor, setter or property typed as a collection would reject that value. Symfony 8.2 changes the handoff so it can respect the collection type the target declares.
For a concrete class such as ArrayCollection, the Serializer creates that class and fills it with the denormalized objects. When the target is typed against the Collection interface, a new CollectionDenormalizer in the Doctrine bridge supplies an ArrayCollection by default. A payload containing member data can therefore become a collection of Member objects rather than an array of those objects.
Array-compatible targets keep their previous behavior. A property typed as array, an untyped property, or an adder method that accepts an array still receives an array. The same collection handling also applies when request data is mapped with #[MapRequestPayload]. For API and request-processing code, this reduces the need to translate deserialized arrays into collection objects after the fact.
Messenger can manage DBAL connections directly
Doctrine’s Messenger middleware previously worked through an entity manager. That left applications using Doctrine DBAL without the ORM unable to use those tools for connection checks, transaction handling and related work. Symfony 8.2 adds four middleware that operate on DBAL connections directly: doctrine_dbal_ping_connection, doctrine_dbal_close_connection, doctrine_dbal_transaction and doctrine_dbal_open_transaction_logger.
The ping and transaction logger middleware apply to all DBAL connections when configured without a connection name. Close and transaction middleware can be given a specific connection; the transaction middleware uses the default connection if no name is supplied. These names require DoctrineBundle 3.4 or higher.
The shift broadens which Messenger setups can use database connection management. It also changes the scope developers should consider when configuring middleware: the earlier close and transaction logger middleware acted only on the connection belonging to the default entity manager, while the new DBAL options can apply across connections. Check which connections a bus should touch before enabling a middleware without a name.
Less configuration, with version boundaries
These updates don’t change Doctrine’s core model of entities, fields or database connections. They reduce manual work at integration points: discovery can replace directory mappings, property types can determine a common date column type, deserialization can preserve collection declarations, and Messenger can work without an ORM entity manager.
The practical payoff depends on the application. Entity discovery needs ORM 3.6 or newer and depends on Symfony scanning the relevant classes. The DBAL middleware needs DoctrineBundle 3.4 or newer. DatePoint inference still leaves specialized types explicit, and custom field mappers retain precedence. Those are the details to check during an upgrade; after that, the clearest sign of success is less duplicate configuration without a change to how the application’s existing data structures are meant to work.