Object-Relational Mapping
Subject: Computer and Technology noun /ˈɑːb.dʒɪkt rɪˈleɪ.ʃən.əl ˈmæp.ɪŋ/ 1 definition
- database-systems
- software-engineering
- data-modeling
- object-oriented-programming
-
Definition (noun)
Entry #69 · UpdatedObject-Relational Mapping (ORM) is a programming technique and software abstraction layer that translates data between relational database schemas and object-oriented structures in application code. By bridging the object-relational impedance mismatch—where normalized tables, rows, and foreign keys differ from in-memory object graphs and inheritance—an ORM lets developers query and persist records through native language models rather than writing boilerplate SQL and manually hydrating results. Sitting above the database driver rather than replacing the relational engine itself, an ORM accelerates development and improves maintainability, though complex analytical queries or tight latency targets often require raw SQL or careful control over generated joins and lazy loading.
Common Forms
Active Record: Embeds persistence logic directly inside domain model classes, so each object instance corresponds to a database row and exposes methods such as
save()anddelete()(such as Ruby on Rails and Django).Data Mapper: Separates in-memory domain objects from database persistence through an intermediary mapper or unit-of-work layer, keeping business entities decoupled from the underlying relational schema (such as SQLAlchemy and Hibernate).
Micro-ORM: Provides a lightweight mapping layer focused on fast SQL execution and mapping query result rows into typed objects, omitting heavyweight features such as automatic change tracking, lazy loading, and schema migrations (such as Dapper).
Schema-Driven ORM: Uses a declarative schema file or database introspection at build time to generate strongly typed client models and query builders rather than relying solely on runtime reflection (such as Prisma).
Example
When an e-commerce checkout service in Java loads a customer's shopping cart via Hibernate, the ORM generates a parameterized
SELECTquery joining thecartsandline_itemstables in PostgreSQL and populates typedCartandLineItemobjects in memory. After the service updates an item quantity and commits the transaction, Hibernate's dirty checking detects the modified field and automatically issues the correspondingUPDATEstatement without the developer writing manual SQL.