What is an ORM (Object Relational Mapping) ?

By | 29 June, 2016
Share Article


Many of you heard a term ORM or Object Relational Mapping and thought that What is an ORM (Object Relational Mapping) ? ORM is a short form of Object Relational Mapping. ORM is a concept which encapsulate relational database schema and provide a object oriented interface to developers. ORM framework as are developed using an object oriented programming language like PHP, Java etc. ORM allow developers to query and manipulate the data from a relational database using an object oriented paradigm. ORM wrap around the relational database system (RDBMS) and create a virtual object oriented database that is used within and from the programming language.
Basically ORM define a mapping between your classes and database tables or class members and table columns and the ORM manage the communication between your codes and underlying database. ORM framework wrap relation database tables into the classes of programming language, so that instead of writing SQL queries to manipulate database, we can use methods and objects.


Now question is that Why i use ORM frameworks? What are advantages of ORM ? So, here is your answer

Advantages of using ORM frameworks

  1. ORM framework protect you application against the SQL injection attacks. Hence the ORM frameworks filter and sanitize all data. So, you don’t need to worry about this.
  2. Since ORM handle all database related things like writing SQL statements, data type conversions etc. SO, it become easy in future if you want to change the database server of your application. Like your application currently use MySql and you need to use PostgreSQL as database. It become very easy and need very less efforts if you use an ORM. By the way in my six year of experience i seen this case only once.
  3. If you have more then 10 tables and more then 3 developers are working on an application. Then it is helpful to use ORM framework. Because ORM framework create a consistent code style for your application. So, it becomes easy to work and probability of meshing up become less.
  4. There are lots of stuffs are done automatically for you by ORM frameworks. For example database handling, table relations & joins, filtering data, I18N etc.
  5. It make the maintenance work easy for you. Because ORM framework follow DRY practice. So, you have to write your data models only at one place. So, it become easy to maintain and update codes.
  6. A good ORM take care of synchronisation of the data types between the programming language (Ex. PHP, Java) and the SQL database. So, it also handle the data type conversion related things for you.
  7. ORM supports to ACID properties and transactions (commit and rollback).

If i am not wrong now you are thinking that Does there are some drawbacks of using ORM framework. So, here is your answer

Disadvantages of using ORM frameworks

  1. You have to learn the ORM framework first. There is a learning curve in understanding and using ORM framework.
  2. ORM makes working easier. But unfortunately developers skip learning SQL and database related things.
  3. Performance is fine for normal queries. But but you can always do better with your own SQL queries.
  4. Some time ORM fails to compete against native SQL queries incase of complex queries.

4 thoughts on “What is an ORM (Object Relational Mapping) ?

  1. Atanas Markov

    If you have more then 10 tables and more then 3 developers are working on an application. Then it is helpful to use ORM framework.

    Hmmm… A little wrong. If you have 100 tables with 5 000 000 records and gigs in some of them, foreign key relations in tables and on top of that need the system to work RUN AWAY FROM ORM. Applications just lag, I have seen java android app to make phone hot on 10000 records using orm and then work 100 times faster and no heat with 2000000 records, 5000 coming each second for testing when skipping orm in favour of sql. Php project to give realtime reports and refresh data on large dbs. Forget it with orm. Doctrine makes apis to need something like 300mb and respond in 1-2s where raw sql and less php oo overhead will work with 4-6mb ram usage and 0.01s needed to complete.

    You don’t need to change db each day and this usually means code rewrite. Many of the “advantages” of orm cited are fake if people think from real world cases point of view.

    Orm is good only for small, very little loads, standard crud(no analysis and complex reports) sites/apps or prototypes. Bloated code they force you to write makes dev speed go down on more compelxity- something like using all bloat 5 men to write for a year what in raw php olus sql will be done by 1 in a month(and this plus the performance and more dificult support problems of bloated code).

    1. admin Post author

      @Atanas Native SQL Queries are always faster than any other library like ORM or Active Records etc. This all depends on your application and architecture. Each coin has two sides same in this case there are both pros and cons of ORM.

  2. Demarcus Cauthon

    For this reason, many programmers find themselves more at home with an object-SQL mapping system, even though most object-oriented databases are able to process SQL queries to a limited extent.


Leave a Reply

Your email address will not be published. Required fields are marked *