PHP Classes

File: docs/guides/aem-and-doctrine.md

Recommend this page to a friend!
  Packages of ?????? ???????   Adaptive Entity Manager   docs/guides/aem-and-doctrine.md   Download  
File: docs/guides/aem-and-doctrine.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Adaptive Entity Manager
Entity manager to work with multiple data sources
Author: By
Last change:
Date: 3 months ago
Size: 4,477 bytes
 

 

Contents

Class file image Download

AEM and Doctrine

How Adaptive Entity Manager relates to Doctrine Persistence (ObjectManager), DBAL, and Doctrine ORM?and when to use each.

AEM implements Doctrine\Persistence\ObjectManager. It is not a Doctrine ORM replacement. Many teams use AEM long term with DBAL and custom adapters; moving a context to ORM is optional (RFC-004).

Architecture comparison

graph TD
    subgraph aemFlow [Adaptive Entity Manager]
        AEM_BL["Application / domain"]
        AEM_Repo["Repository port or AEM repository"]
        AEM_Manager["AdaptiveEntityManager"]
        AEM_UOW["UnitOfWork"]
        AEM_Persister["EntityPersister"]
        AEM_Adapter["EntityDataAdapter"]
        AEM_DS["DB / API / files"]

        AEM_BL --> AEM_Repo
        AEM_Repo --> AEM_Manager
        AEM_Manager --> AEM_UOW
        AEM_UOW --> AEM_Persister
        AEM_Persister --> AEM_Adapter
        AEM_Adapter --> AEM_DS
    end

    subgraph doctrineFlow [Doctrine ORM]
        DOC_BL["Application / domain"]
        DOC_Repo["Repository"]
        DOC_Manager["EntityManager"]
        DOC_UOW["UnitOfWork"]
        DOC_Persister["EntityPersister"]
        DOC_DBAL["DBAL"]
        DOC_DB["Relational database"]

        DOC_BL --> DOC_Repo
        DOC_Repo --> DOC_Manager
        DOC_Manager --> DOC_UOW
        DOC_UOW --> DOC_Persister
        DOC_Persister --> DOC_DBAL
        DOC_DBAL --> DOC_DB
    end

What each piece is for

Adaptive Entity Manager

  • Adaptive mapper for legacy DBs, mixed sources, and incremental modernization
  • Pluggable adapters ? one `ObjectManager`-style API over SQL, HTTP, files, etc.
  • Metadata-driven entities without full ORM mapping discipline
  • Valid long-term choice when sources stay heterogeneous (migration roadmap)

Doctrine DBAL

  • Connections, SQL, query builder ? often used inside AEM adapters
  • AEM fits when you want DBAL (or similar) without adopting ORM entity graphs everywhere

Doctrine ORM

  • Full relational ORM: entities, associations, migrations ecosystem, DQL
  • Best when one bounded context owns a stable relational model and the team standardizes on ORM

Comparison at a glance

| Aspect | AEM | Doctrine ORM | |--------|-----|--------------| | Primary fit | Legacy, multi-source, hexagonal infra | Single relational core, long-lived ORM | | Data access | EntityDataAdapter | DBAL + mapping | | Query language | Adapter/criteria (no DQL in AEM) | DQL, QueryBuilder | | ObjectManager | Yes (AEM API) | Yes (EntityManager) | | Non-DB sources | First-class via adapters | Not first-class |

When to choose AEM

  • Several data sources or awkward legacy schemas
  • DBAL/SQL in adapters but ORM mapping is impractical
  • Incremental extraction of bounded contexts
  • Hexagonal layout: repositories as ports, AEM in adapters
  • Value objects and metadata mapping (VALUE_OBJECTS.md)

When to choose Doctrine ORM (instead of or beside AEM)

  • Architecture stabilized on one relational database for a context
  • Complex associations and DQL are central
  • Team and tooling (migrations, bundles) assume ORM

You can run AEM for some contexts and ORM for others. Optional cutover steps: RFC-004.

Common combinations

| Pattern | Description | |---------|-------------| | AEM + DBAL in adapter | SQL legacy DB; connection and queries in adapter; entities via AEM metadata | | AEM only | DB + REST + files through different adapters; no ORM | | ORM for one BC, AEM elsewhere | New core on PostgreSQL with Doctrine; legacy slice still on AEM until retired | | ObjectManager familiarity | Teams know Doctrine persistence interfaces; AEM feels familiar without ORM |

What AEM does not provide

  • DQL or ORM-style association graph (by design ? see RFC-004)
  • Doctrine Migrations / bundles as a bundled story (use your stack separately)
  • Replacement for every Doctrine ORM extension

Related guides