OR Mapping

Object-relational mapping (also ORM and O/R Mapping) is a technique used in software engineering to bridge the gap between object-oriented programming (OOP) and relational databases. OR Mapping converts data between a database and an object-oriented programming language.

ORM allows developers to work with database records as if they were objects in their programming language, abstracting away the complexities of SQL queries and database interactions.

How Does ORM Work?

  • Mapping: ORM maps database tables to classes (objects) in the application code.
  • CRUD Operations: Developers can perform CRUD (Create, Read, Update, Delete) operations on objects, and the ORM translates these actions into corresponding SQL statements.
  • Relationships: ORM handles relationships (such as one-to-many, many-to-many) between objects and their associated database tables.

Benefits of ORM:

  • Productivity: Developers can focus on business logic rather than writing raw SQL queries.
  • Portability: ORM makes it easier to switch between different database systems (e.g., MySQL, PostgreSQL, SQLite) without changing application code.
  • Security: ORM helps prevent SQL injection attacks by parameterizing queries.
  • Abstraction: Developers work with objects, abstracting away low-level database details.

ORM simplifies database interactions by allowing developers to work with objects in their code, while the ORM handles the underlying database operations. It’s a powerful tool for building robust and maintainable software systems.

Other OR mappers

Entity framework from Microsoft, Hibernate for Java or .net or Django's ORM are all OR mappers, although simpler than MDriven's OR mapper and all lacking modelling support.

Learn more here: Object–relational mapping

See also: Type mapping, OR-Mapping, Working with Code and Persistence Mapping

This page was edited 152 days ago on 06/24/2024. What links here