What is an ORM and what are its trade-offs?
Answer
An ORM (Object-Relational Mapper) maps database tables to classes and rows to objects in your programming language, allowing you to query and manipulate data using the language's native paradigm instead of writing SQL. Examples: Hibernate (Java), ActiveRecord (Rails), SQLAlchemy (Python), Entity Framework (.NET), Eloquent (Laravel). Benefits: faster development, database abstraction (switch RDBMS with minimal code changes), protection against SQL injection (parameterized queries). Trade-offs: generated SQL can be inefficient or cause N+1 queries, learning curve of the ORM API, and complex queries are often cleaner in raw SQL. Most ORMs allow dropping to raw SQL when needed.
Previous
What is the difference between horizontal and vertical scaling of databases?
Next
What is the difference between optimistic and pessimistic locking?
More Database Design / Normalization Questions
View all →- Intermediate What are database anomalies and how does normalization prevent them?
- Intermediate What is denormalization and when is it used?
- Intermediate What are isolation levels in database transactions?
- Intermediate What are dirty reads, non-repeatable reads, and phantom reads?
- Intermediate What is query optimization and what is a query execution plan?