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
- 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.
- 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.
- 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.
- There are lots of stuffs are done automatically for you by ORM frameworks. For example database handling, table relations & joins, filtering data, I18N etc.
- 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.
- 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.
- 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
- You have to learn the ORM framework first. There is a learning curve in understanding and using ORM framework.
- ORM makes working easier. But unfortunately developers skip learning SQL and database related things.
- Performance is fine for normal queries. But but you can always do better with your own SQL queries.
- Some time ORM fails to compete against native SQL queries incase of complex queries.